2010-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Removed SharedHandle::isNull(). Instead we added operator* and
	operator unspecified_bool_type. Removed use of WeakHandle and
	replaced with raw pointer.
This commit is contained in:
Tatsuhiro Tsujikawa 2010-11-12 12:48:48 +00:00
parent f6f5a7e5ee
commit 93e5dbed32
181 changed files with 911 additions and 876 deletions

View file

@ -1,3 +1,9 @@
2010-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed SharedHandle::isNull(). Instead we added operator* and
operator unspecified_bool_type. Removed use of WeakHandle and
replaced with raw pointer.
2010-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed memory leak Fixed memory leak

View file

@ -48,6 +48,10 @@ AbstractBtMessage::AbstractBtMessage(uint8_t id, const std::string& name):
uploading_(false), uploading_(false),
cuid_(0), cuid_(0),
name_(name), name_(name),
dispatcher_(0),
messageFactory_(0),
requestFactory_(0),
peerConnection_(0),
metadataGetMode_(false), metadataGetMode_(false),
logger_(LogFactory::getInstance()) logger_(LogFactory::getInstance())
{} {}
@ -61,7 +65,7 @@ void AbstractBtMessage::setPeer(const SharedHandle<Peer>& peer)
void AbstractBtMessage::validate() void AbstractBtMessage::validate()
{ {
if(!validator_.isNull()) { if(validator_) {
validator_->validate(); validator_->validate();
} }
} }
@ -77,23 +81,22 @@ void AbstractBtMessage::setPieceStorage
pieceStorage_ = pieceStorage; pieceStorage_ = pieceStorage;
} }
void AbstractBtMessage::setBtMessageDispatcher void AbstractBtMessage::setBtMessageDispatcher(BtMessageDispatcher* dispatcher)
(const WeakHandle<BtMessageDispatcher>& dispatcher)
{ {
dispatcher_ = dispatcher; dispatcher_ = dispatcher;
} }
void AbstractBtMessage::setPeerConnection(const WeakHandle<PeerConnection>& peerConnection) void AbstractBtMessage::setPeerConnection(PeerConnection* peerConnection)
{ {
peerConnection_ = peerConnection; peerConnection_ = peerConnection;
} }
void AbstractBtMessage::setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory) void AbstractBtMessage::setBtMessageFactory(BtMessageFactory* factory)
{ {
messageFactory_ = factory; messageFactory_ = factory;
} }
void AbstractBtMessage::setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory) void AbstractBtMessage::setBtRequestFactory(BtRequestFactory* factory)
{ {
requestFactory_ = factory; requestFactory_ = factory;
} }

View file

@ -62,13 +62,13 @@ private:
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;
WeakHandle<BtMessageDispatcher> dispatcher_; BtMessageDispatcher* dispatcher_;
WeakHandle<BtMessageFactory> messageFactory_; BtMessageFactory* messageFactory_;
WeakHandle<BtRequestFactory> requestFactory_; BtRequestFactory* requestFactory_;
WeakHandle<PeerConnection> peerConnection_; PeerConnection* peerConnection_;
SharedHandle<BtMessageValidator> validator_; SharedHandle<BtMessageValidator> validator_;
@ -86,22 +86,22 @@ protected:
return pieceStorage_; return pieceStorage_;
} }
const WeakHandle<PeerConnection>& getPeerConnection() const PeerConnection* getPeerConnection() const
{ {
return peerConnection_; return peerConnection_;
} }
const WeakHandle<BtMessageDispatcher>& getBtMessageDispatcher() const BtMessageDispatcher* getBtMessageDispatcher() const
{ {
return dispatcher_; return dispatcher_;
} }
const WeakHandle<BtRequestFactory>& getBtRequestFactory() const BtRequestFactory* getBtRequestFactory() const
{ {
return requestFactory_; return requestFactory_;
} }
const WeakHandle<BtMessageFactory>& getBtMessageFactory() const BtMessageFactory* getBtMessageFactory() const
{ {
return messageFactory_; return messageFactory_;
} }
@ -172,14 +172,13 @@ public:
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage); void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
void setBtMessageDispatcher void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
(const WeakHandle<BtMessageDispatcher>& dispatcher);
void setPeerConnection(const WeakHandle<PeerConnection>& peerConnection); void setPeerConnection(PeerConnection* peerConnection);
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory); void setBtMessageFactory(BtMessageFactory* factory);
void setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory); void setBtRequestFactory(BtRequestFactory* factory);
const std::string& getName() const const std::string& getName() const
{ {

View file

@ -90,7 +90,7 @@ AbstractCommand::AbstractCommand(cuid_t cuid,
nameResolverCheck_(false), nameResolverCheck_(false),
incNumConnection_(incNumConnection) incNumConnection_(incNumConnection)
{ {
if(!socket_.isNull() && socket_->isOpen()) { if(socket_ && socket_->isOpen()) {
setReadCheckSocket(socket_); setReadCheckSocket(socket_);
} }
if(incNumConnection_) { if(incNumConnection_) {
@ -126,7 +126,7 @@ bool AbstractCommand::execute() {
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) { if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
return true; return true;
} }
if(!req_.isNull() && req_->removalRequested()) { if(req_ && req_->removalRequested()) {
if(getLogger()->debug()) { if(getLogger()->debug()) {
getLogger()->debug getLogger()->debug
("CUID#%s - Discard original URI=%s because it is requested.", ("CUID#%s - Discard original URI=%s because it is requested.",
@ -134,10 +134,10 @@ bool AbstractCommand::execute() {
} }
return prepareForRetry(0); return prepareForRetry(0);
} }
if(!getPieceStorage().isNull()) { if(getPieceStorage()) {
segments_.clear(); segments_.clear();
getSegmentMan()->getInFlightSegment(segments_, getCuid()); getSegmentMan()->getInFlightSegment(segments_, getCuid());
if(!req_.isNull() && segments_.empty()) { if(req_ && segments_.empty()) {
// This command previously has assigned segments, but it is // This command previously has assigned segments, but it is
// canceled. So discard current request chain. Plus, if no // canceled. So discard current request chain. Plus, if no
// segment is available when http pipelining is used. // segment is available when http pipelining is used.
@ -149,17 +149,17 @@ bool AbstractCommand::execute() {
// Request::isPipeliningEnabled() == true means aria2 // Request::isPipeliningEnabled() == true means aria2
// accessed the remote server and discovered that the server // accessed the remote server and discovered that the server
// supports pipelining. // supports pipelining.
if(!req_.isNull() && req_->isPipeliningEnabled()) { if(req_ && req_->isPipeliningEnabled()) {
e_->poolSocket(req_, createProxyRequest(), socket_); e_->poolSocket(req_, createProxyRequest(), socket_);
} }
return prepareForRetry(0); return prepareForRetry(0);
} }
// TODO it is not needed to check other PeerStats every time. // TODO it is not needed to check other PeerStats every time.
// Find faster Request when no segment is available. // Find faster Request when no segment is available.
if(!req_.isNull() && fileEntry_->countPooledRequest() > 0 && if(req_ && fileEntry_->countPooledRequest() > 0 &&
!getPieceStorage()->hasMissingUnusedPiece()) { !getPieceStorage()->hasMissingUnusedPiece()) {
SharedHandle<Request> fasterRequest = fileEntry_->findFasterRequest(req_); SharedHandle<Request> fasterRequest = fileEntry_->findFasterRequest(req_);
if(!fasterRequest.isNull()) { if(fasterRequest) {
if(getLogger()->info()) { if(getLogger()->info()) {
getLogger()->info("CUID#%s - Use faster Request hostname=%s, port=%u", getLogger()->info("CUID#%s - Use faster Request hostname=%s, port=%u",
util::itos(getCuid()).c_str(), util::itos(getCuid()).c_str(),
@ -186,18 +186,18 @@ bool AbstractCommand::execute() {
(!checkSocketIsReadable_ && !checkSocketIsWritable_ && (!checkSocketIsReadable_ && !checkSocketIsWritable_ &&
!nameResolverCheck_)) { !nameResolverCheck_)) {
checkPoint_ = global::wallclock; checkPoint_ = global::wallclock;
if(!getPieceStorage().isNull()) { if(getPieceStorage()) {
if(req_.isNull() || req_->getMaxPipelinedRequest() == 1 || if(!req_ || req_->getMaxPipelinedRequest() == 1 ||
// Why the following condition is necessary? That's because // Why the following condition is necessary? That's because
// For single file download, SegmentMan::getSegment(cuid) // For single file download, SegmentMan::getSegment(cuid)
// is more efficient. // is more efficient.
getDownloadContext()->getFileEntries().size() == 1) { getDownloadContext()->getFileEntries().size() == 1) {
size_t maxSegments = req_.isNull()?1:req_->getMaxPipelinedRequest(); size_t maxSegments = req_?req_->getMaxPipelinedRequest():1;
size_t minSplitSize = calculateMinSplitSize(); size_t minSplitSize = calculateMinSplitSize();
while(segments_.size() < maxSegments) { while(segments_.size() < maxSegments) {
SharedHandle<Segment> segment = SharedHandle<Segment> segment =
getSegmentMan()->getSegment(getCuid(), minSplitSize); getSegmentMan()->getSegment(getCuid(), minSplitSize);
if(segment.isNull()) { if(!segment) {
break; break;
} else { } else {
segments_.push_back(segment); segments_.push_back(segment);
@ -272,7 +272,7 @@ bool AbstractCommand::execute() {
return false; return false;
} }
} catch(DlAbortEx& err) { } catch(DlAbortEx& err) {
if(req_.isNull()) { if(!req_) {
if(getLogger()->debug()) { if(getLogger()->debug()) {
getLogger()->debug(EX_EXCEPTION_CAUGHT, err); getLogger()->debug(EX_EXCEPTION_CAUGHT, err);
} }
@ -292,7 +292,7 @@ bool AbstractCommand::execute() {
tryReserved(); tryReserved();
return true; return true;
} catch(DlRetryEx& err) { } catch(DlRetryEx& err) {
assert(!req_.isNull()); assert(req_);
if(getLogger()->info()) { if(getLogger()->info()) {
getLogger()->info getLogger()->info
(MSG_RESTARTING_DOWNLOAD, (MSG_RESTARTING_DOWNLOAD,
@ -327,7 +327,7 @@ bool AbstractCommand::execute() {
} }
} catch(DownloadFailureException& err) { } catch(DownloadFailureException& err) {
getLogger()->error(EX_EXCEPTION_CAUGHT, err); getLogger()->error(EX_EXCEPTION_CAUGHT, err);
if(!req_.isNull()) { if(req_) {
fileEntry_->addURIResult(req_->getUri(), err.getCode()); fileEntry_->addURIResult(req_->getUri(), err.getCode());
requestGroup_->setLastUriResult(req_->getUri(), err.getCode()); requestGroup_->setLastUriResult(req_->getUri(), err.getCode());
} }
@ -364,16 +364,16 @@ void AbstractCommand::tryReserved() {
} }
bool AbstractCommand::prepareForRetry(time_t wait) { bool AbstractCommand::prepareForRetry(time_t wait) {
if(!getPieceStorage().isNull()) { if(getPieceStorage()) {
getSegmentMan()->cancelSegment(getCuid()); getSegmentMan()->cancelSegment(getCuid());
} }
if(!req_.isNull()) { if(req_) {
fileEntry_->poolRequest(req_); fileEntry_->poolRequest(req_);
if(getLogger()->debug()) { if(getLogger()->debug()) {
getLogger()->debug("CUID#%s - Pooling request URI=%s", getLogger()->debug("CUID#%s - Pooling request URI=%s",
util::itos(getCuid()).c_str(), req_->getUri().c_str()); util::itos(getCuid()).c_str(), req_->getUri().c_str());
} }
if(!getSegmentMan().isNull()) { if(getSegmentMan()) {
getSegmentMan()->recognizeSegmentFor(fileEntry_); getSegmentMan()->recognizeSegmentFor(fileEntry_);
} }
} }
@ -391,7 +391,7 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
} }
void AbstractCommand::onAbort() { void AbstractCommand::onAbort() {
if(!req_.isNull()) { if(req_) {
fileEntry_->removeIdenticalURI(req_->getUri()); fileEntry_->removeIdenticalURI(req_->getUri());
fileEntry_->removeRequest(req_); fileEntry_->removeRequest(req_);
} }
@ -399,13 +399,13 @@ void AbstractCommand::onAbort() {
getLogger()->debug("CUID#%s - Aborting download", getLogger()->debug("CUID#%s - Aborting download",
util::itos(getCuid()).c_str()); util::itos(getCuid()).c_str());
} }
if(!getPieceStorage().isNull()) { if(getPieceStorage()) {
getSegmentMan()->cancelSegment(getCuid()); getSegmentMan()->cancelSegment(getCuid());
// Don't do following process if BitTorrent is involved or files // Don't do following process if BitTorrent is involved or files
// in DownloadContext is more than 1. The latter condition is // in DownloadContext is more than 1. The latter condition is
// limitation of current implementation. // limitation of current implementation.
if(!getOption()->getAsBool(PREF_ALWAYS_RESUME) && if(!getOption()->getAsBool(PREF_ALWAYS_RESUME) &&
!fileEntry_.isNull() && fileEntry_ &&
getSegmentMan()->calculateSessionDownloadLength() == 0 && getSegmentMan()->calculateSessionDownloadLength() == 0 &&
!requestGroup_->p2pInvolved() && !requestGroup_->p2pInvolved() &&
getDownloadContext()->getFileEntries().size() == 1) { getDownloadContext()->getFileEntries().size() == 1) {
@ -660,7 +660,7 @@ SharedHandle<Request> AbstractCommand::createProxyRequest() const
bool AbstractCommand::isAsyncNameResolverInitialized() const bool AbstractCommand::isAsyncNameResolverInitialized() const
{ {
return !asyncNameResolver_.isNull(); return asyncNameResolver_;
} }
void AbstractCommand::initAsyncNameResolver(const std::string& hostname) void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
@ -709,7 +709,7 @@ const std::vector<std::string>& AbstractCommand::getResolvedAddresses()
void AbstractCommand::setNameResolverCheck void AbstractCommand::setNameResolverCheck
(const SharedHandle<AsyncNameResolver>& resolver) { (const SharedHandle<AsyncNameResolver>& resolver) {
if(!resolver.isNull()) { if(resolver) {
nameResolverCheck_ = true; nameResolverCheck_ = true;
e_->addNameResolverCheck(resolver, this); e_->addNameResolverCheck(resolver, this);
} }
@ -717,7 +717,7 @@ void AbstractCommand::setNameResolverCheck
void AbstractCommand::disableNameResolverCheck void AbstractCommand::disableNameResolverCheck
(const SharedHandle<AsyncNameResolver>& resolver) { (const SharedHandle<AsyncNameResolver>& resolver) {
if(!resolver.isNull()) { if(resolver) {
nameResolverCheck_ = false; nameResolverCheck_ = false;
e_->deleteNameResolverCheck(resolver, this); e_->deleteNameResolverCheck(resolver, this);
} }
@ -854,7 +854,7 @@ void AbstractCommand::createSocket()
size_t AbstractCommand::calculateMinSplitSize() const size_t AbstractCommand::calculateMinSplitSize() const
{ {
if(!req_.isNull() && req_->isPipeliningEnabled()) { if(req_ && req_->isPipeliningEnabled()) {
return getDownloadContext()->getPieceLength(); return getDownloadContext()->getPieceLength();
} else { } else {
return getOption()->getAsInt(PREF_MIN_SPLIT_SIZE); return getOption()->getAsInt(PREF_MIN_SPLIT_SIZE);

View file

@ -68,7 +68,7 @@ AbstractProxyResponseCommand::~AbstractProxyResponseCommand() {}
bool AbstractProxyResponseCommand::executeInternal() { bool AbstractProxyResponseCommand::executeInternal() {
SharedHandle<HttpResponse> httpResponse = httpConnection_->receiveResponse(); SharedHandle<HttpResponse> httpResponse = httpConnection_->receiveResponse();
if(httpResponse.isNull()) { if(!httpResponse) {
// the server has not responded our request yet. // the server has not responded our request yet.
getDownloadEngine()->addCommand(this); getDownloadEngine()->addCommand(this);
return false; return false;

View file

@ -135,7 +135,7 @@ bool ActivePeerConnectionCommand::execute() {
void ActivePeerConnectionCommand::connectToPeer(const SharedHandle<Peer>& peer) void ActivePeerConnectionCommand::connectToPeer(const SharedHandle<Peer>& peer)
{ {
if(peer.isNull()) { if(!peer) {
return; return;
} }
peer->usedBy(e_->newCUID()); peer->usedBy(e_->newCUID());

View file

@ -53,7 +53,7 @@ AdaptiveFileAllocationIterator::~AdaptiveFileAllocationIterator() {}
void AdaptiveFileAllocationIterator::allocateChunk() void AdaptiveFileAllocationIterator::allocateChunk()
{ {
if(allocator_.isNull()) { if(!allocator_) {
#ifdef HAVE_FALLOCATE #ifdef HAVE_FALLOCATE
try { try {
if(logger_->debug()) { if(logger_->debug()) {
@ -92,7 +92,7 @@ void AdaptiveFileAllocationIterator::allocateChunk()
bool AdaptiveFileAllocationIterator::finished() bool AdaptiveFileAllocationIterator::finished()
{ {
if(allocator_.isNull()) { if(!allocator_) {
return (uint64_t)offset_ == totalLength_; return (uint64_t)offset_ == totalLength_;
} else { } else {
return allocator_->finished(); return allocator_->finished();

View file

@ -66,7 +66,7 @@ public:
virtual off_t getCurrentLength() virtual off_t getCurrentLength()
{ {
if(allocator_.isNull()) { if(!allocator_) {
return offset_; return offset_;
} else { } else {
return allocator_->getCurrentLength(); return allocator_->getCurrentLength();

View file

@ -266,7 +266,7 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri
for(std::deque<std::string>::const_iterator i = uris.begin(), for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) { eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i); SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull()) if(!ss)
continue; continue;
if((int)ss->getSingleConnectionAvgSpeed() > max) { if((int)ss->getSingleConnectionAvgSpeed() > max) {
@ -288,7 +288,7 @@ std::deque<std::string> AdaptiveURISelector::getUrisBySpeed
for(std::deque<std::string>::const_iterator i = uris.begin(), for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) { eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i); SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull()) if(!ss)
continue; continue;
if(ss->getSingleConnectionAvgSpeed() > min || if(ss->getSingleConnectionAvgSpeed() > min ||
ss->getMultiConnectionAvgSpeed() > min) { ss->getMultiConnectionAvgSpeed() > min) {
@ -313,7 +313,7 @@ std::string AdaptiveURISelector::getFirstNotTestedUri
for(std::deque<std::string>::const_iterator i = uris.begin(), for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) { eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i); SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull()) if(!ss)
return *i; return *i;
} }
return A2STR::NIL; return A2STR::NIL;
@ -327,7 +327,7 @@ std::string AdaptiveURISelector::getFirstToTestUri
for(std::deque<std::string>::const_iterator i = uris.begin(), for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) { eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i); SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull()) if(!ss)
continue; continue;
counter = ss->getCounter(); counter = ss->getCounter();
if(counter > 8) if(counter > 8)
@ -360,7 +360,7 @@ unsigned int AdaptiveURISelector::getNbTestedServers
for(std::deque<std::string>::const_iterator i = uris.begin(), for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) { eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i); SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull()) if(!ss)
++counter; ++counter;
} }
return uris.size() - counter; return uris.size() - counter;

View file

@ -97,7 +97,7 @@ AuthConfigFactory::createAuthConfig
SharedHandle<AuthConfig> ac = SharedHandle<AuthConfig> ac =
authResolver.resolveAuthConfig(request->getHost()); authResolver.resolveAuthConfig(request->getHost());
if(!ac.isNull() && ac->getUser() == request->getUsername()) { if(ac && ac->getUser() == request->getUsername()) {
return ac; return ac;
} }
} }
@ -187,7 +187,7 @@ bool AuthConfigFactory::activateBasicCred
if(i == basicCreds_.end()) { if(i == basicCreds_.end()) {
SharedHandle<AuthConfig> authConfig = SharedHandle<AuthConfig> authConfig =
createHttpAuthResolver(op)->resolveAuthConfig(host); createHttpAuthResolver(op)->resolveAuthConfig(host);
if(authConfig.isNull()) { if(!authConfig) {
return false; return false;
} else { } else {
BasicCred bc(authConfig->getUser(), authConfig->getPassword(), BasicCred bc(authConfig->getUser(), authConfig->getPassword(),

View file

@ -78,7 +78,7 @@ void BNode::setBucket(const SharedHandle<DHTBucket>& bucket)
bool BNode::isInRange(const unsigned char* key) const bool BNode::isInRange(const unsigned char* key) const
{ {
if(bucket_.isNull()) { if(!bucket_) {
return left_->isInRange(key) || right_->isInRange(key); return left_->isInRange(key) || right_->isInRange(key);
} else { } else {
return bucket_->isInRange(key); return bucket_->isInRange(key);
@ -91,7 +91,7 @@ BNode* BNode::findBNodeFor(BNode* b, const unsigned char* key)
return 0; return 0;
} }
while(1) { while(1) {
if(!b->getBucket().isNull()) { if(b->getBucket()) {
return b; return b;
} }
// we assume key fits in either left or right bucket range. // we assume key fits in either left or right bucket range.
@ -164,7 +164,7 @@ void BNode::findClosestKNodes(std::vector<SharedHandle<DHTNode> >& nodes,
visited.push_back(bnode); visited.push_back(bnode);
{ {
SharedHandle<DHTBucket> bucket = bnode->getBucket(); SharedHandle<DHTBucket> bucket = bnode->getBucket();
if(!bucket.isNull()) { if(bucket) {
std::vector<SharedHandle<DHTNode> > goodNodes; std::vector<SharedHandle<DHTNode> > goodNodes;
bucket->getGoodNodes(goodNodes); bucket->getGoodNodes(goodNodes);
size_t r = DHTBucket::K-nodes.size(); size_t r = DHTBucket::K-nodes.size();
@ -187,7 +187,7 @@ void BNode::enumerateBucket(std::vector<SharedHandle<DHTBucket> >& buckets,
if(!b) { if(!b) {
break; break;
} }
if(!b->getBucket().isNull()) { if(b->getBucket()) {
buckets.push_back(b->getBucket()); buckets.push_back(b->getBucket());
b = b->getUp(); b = b->getUp();
} else if(std::find(visited.begin(), visited.end(), b->getLeft()) == visited.end()) { } else if(std::find(visited.begin(), visited.end(), b->getLeft()) == visited.end()) {

View file

@ -51,7 +51,7 @@
namespace aria2 { namespace aria2 {
BtDependency::BtDependency(const WeakHandle<RequestGroup>& dependant, BtDependency::BtDependency(RequestGroup* dependant,
const SharedHandle<RequestGroup>& dependee): const SharedHandle<RequestGroup>& dependee):
dependant_(dependant), dependant_(dependant),
dependee_(dependee), dependee_(dependee),

View file

@ -46,11 +46,11 @@ class Logger;
class BtDependency : public Dependency class BtDependency : public Dependency
{ {
private: private:
WeakHandle<RequestGroup> dependant_; RequestGroup* dependant_;
SharedHandle<RequestGroup> dependee_; SharedHandle<RequestGroup> dependee_;
Logger* logger_; Logger* logger_;
public: public:
BtDependency(const WeakHandle<RequestGroup>& dependant, BtDependency(RequestGroup* dependant,
const SharedHandle<RequestGroup>& dependee); const SharedHandle<RequestGroup>& dependee);
virtual ~BtDependency(); virtual ~BtDependency();

View file

@ -99,7 +99,7 @@ BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& factory,
{ {
bittorrent::assertPayloadLengthGreater(1, dataLength, NAME); bittorrent::assertPayloadLengthGreater(1, dataLength, NAME);
bittorrent::assertID(ID, data, NAME); bittorrent::assertID(ID, data, NAME);
assert(!factory.isNull()); assert(factory);
ExtensionMessageHandle extmsg = factory->createMessage(data+1, ExtensionMessageHandle extmsg = factory->createMessage(data+1,
dataLength-1); dataLength-1);
BtExtendedMessageHandle message(new BtExtendedMessage(extmsg)); BtExtendedMessageHandle message(new BtExtendedMessage(extmsg));
@ -108,7 +108,7 @@ BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& factory,
void BtExtendedMessage::doReceivedAction() void BtExtendedMessage::doReceivedAction()
{ {
if(!extensionMessage_.isNull()) { if(extensionMessage_) {
extensionMessage_->doReceivedAction(); extensionMessage_->doReceivedAction();
} }
} }

View file

@ -88,7 +88,6 @@ public:
}; };
typedef SharedHandle<BtMessageDispatcher> BtMessageDispatcherHandle; typedef SharedHandle<BtMessageDispatcher> BtMessageDispatcherHandle;
typedef WeakHandle<BtMessageDispatcher> BtMessageDispatcherWeakHandle;
} // namespace aria2 } // namespace aria2

View file

@ -98,7 +98,6 @@ public:
}; };
typedef SharedHandle<BtMessageFactory> BtMessageFactoryHandle; typedef SharedHandle<BtMessageFactory> BtMessageFactoryHandle;
typedef WeakHandle<BtMessageFactory> BtMessageFactoryWeakHandle;
} // namespace aria2 } // namespace aria2

View file

@ -55,7 +55,6 @@ public:
}; };
typedef SharedHandle<BtMessageReceiver> BtMessageReceiverHandle; typedef SharedHandle<BtMessageReceiver> BtMessageReceiverHandle;
typedef WeakHandle<BtMessageReceiver> BtMessageReceiverWeakHandle;
} // namespace aria2 } // namespace aria2

View file

@ -52,7 +52,12 @@ namespace aria2 {
const std::string BtPortMessage::NAME("port"); const std::string BtPortMessage::NAME("port");
BtPortMessage::BtPortMessage(uint16_t port): BtPortMessage::BtPortMessage(uint16_t port):
SimpleBtMessage(ID, NAME), port_(port) {} SimpleBtMessage(ID, NAME), port_(port),
localNode_(0),
routingTable_(0),
taskQueue_(0),
taskFactory_(0)
{}
SharedHandle<BtPortMessage> BtPortMessage::create SharedHandle<BtPortMessage> BtPortMessage::create
(const unsigned char* data, size_t dataLength) (const unsigned char* data, size_t dataLength)
@ -66,7 +71,7 @@ SharedHandle<BtPortMessage> BtPortMessage::create
void BtPortMessage::doReceivedAction() void BtPortMessage::doReceivedAction()
{ {
if(!taskFactory_.isNull() && !taskQueue_.isNull()) { if(taskFactory_ && taskQueue_) {
if(port_ == 0) { if(port_ == 0) {
if(getLogger()->debug()) { if(getLogger()->debug()) {
getLogger()->debug("Ignored port 0."); getLogger()->debug("Ignored port 0.");
@ -116,22 +121,22 @@ std::string BtPortMessage::toString() const {
return strconcat(NAME, " port=", util::uitos(port_)); return strconcat(NAME, " port=", util::uitos(port_));
} }
void BtPortMessage::setLocalNode(const WeakHandle<DHTNode>& localNode) void BtPortMessage::setLocalNode(DHTNode* localNode)
{ {
localNode_ = localNode; localNode_ = localNode;
} }
void BtPortMessage::setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable) void BtPortMessage::setRoutingTable(DHTRoutingTable* routingTable)
{ {
routingTable_ = routingTable; routingTable_ = routingTable;
} }
void BtPortMessage::setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue) void BtPortMessage::setTaskQueue(DHTTaskQueue* taskQueue)
{ {
taskQueue_ = taskQueue; taskQueue_ = taskQueue;
} }
void BtPortMessage::setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory) void BtPortMessage::setTaskFactory(DHTTaskFactory* taskFactory)
{ {
taskFactory_ = taskFactory; taskFactory_ = taskFactory;
} }

View file

@ -49,13 +49,13 @@ private:
uint16_t port_; uint16_t port_;
static const size_t MESSAGE_LENGTH = 7; static const size_t MESSAGE_LENGTH = 7;
WeakHandle<DHTNode> localNode_; DHTNode* localNode_;
WeakHandle<DHTRoutingTable> routingTable_; DHTRoutingTable* routingTable_;
WeakHandle<DHTTaskQueue> taskQueue_; DHTTaskQueue* taskQueue_;
WeakHandle<DHTTaskFactory> taskFactory_; DHTTaskFactory* taskFactory_;
public: public:
BtPortMessage(uint16_t port); BtPortMessage(uint16_t port);
@ -76,13 +76,13 @@ public:
virtual std::string toString() const; virtual std::string toString() const;
void setLocalNode(const WeakHandle<DHTNode>& localNode); void setLocalNode(DHTNode* localNode);
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable); void setRoutingTable(DHTRoutingTable* routingTable);
void setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue); void setTaskQueue(DHTTaskQueue* taskQueue);
void setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory); void setTaskFactory(DHTTaskFactory* taskFactory);
}; };
} // namespace aria2 } // namespace aria2

View file

@ -84,7 +84,7 @@ void BtPostDownloadHandler::getNextRequestGroups
requestGroup->followedBy(newRgs.begin(), newRgs.end()); requestGroup->followedBy(newRgs.begin(), newRgs.end());
SharedHandle<MetadataInfo> mi = SharedHandle<MetadataInfo> mi =
createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext()); createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext());
if(!mi.isNull()) { if(mi) {
setMetadataInfo(newRgs.begin(), newRgs.end(), mi); setMetadataInfo(newRgs.begin(), newRgs.end(), mi);
} }
groups.insert(groups.end(), newRgs.begin(), newRgs.end()); groups.insert(groups.end(), newRgs.begin(), newRgs.end());

View file

@ -76,12 +76,12 @@ struct BtObject {
bool isNull() const bool isNull() const
{ {
return downloadContext_.isNull() && return !downloadContext_ &&
pieceStorage_.isNull() && !pieceStorage_ &&
peerStorage_.isNull() && !peerStorage_ &&
btAnnounce_.isNull() && !btAnnounce_ &&
btRuntime_.isNull() && !btRuntime_ &&
btProgressInfoFile_.isNull(); !btProgressInfoFile_;
} }
}; };

View file

@ -88,7 +88,6 @@ public:
}; };
typedef SharedHandle<BtRequestFactory> BtRequestFactoryHandle; typedef SharedHandle<BtRequestFactory> BtRequestFactoryHandle;
typedef WeakHandle<BtRequestFactory> BtRequestFactoryWeakHandle;
} // namespace aria2 } // namespace aria2

View file

@ -61,7 +61,7 @@ void CheckIntegrityEntry::validateChunk()
uint64_t CheckIntegrityEntry::getTotalLength() uint64_t CheckIntegrityEntry::getTotalLength()
{ {
if(validator_.isNull()) { if(!validator_) {
return 0; return 0;
} else { } else {
return validator_->getTotalLength(); return validator_->getTotalLength();
@ -70,7 +70,7 @@ uint64_t CheckIntegrityEntry::getTotalLength()
off_t CheckIntegrityEntry::getCurrentLength() off_t CheckIntegrityEntry::getCurrentLength()
{ {
if(validator_.isNull()) { if(!validator_) {
return 0; return 0;
} else { } else {
return validator_->getCurrentOffset(); return validator_->getCurrentOffset();

View file

@ -121,7 +121,7 @@ void printProgress
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
SharedHandle<PeerStorage> ps = SharedHandle<PeerStorage> ps =
e->getBtRegistry()->get(rg->getGID()).peerStorage_; e->getBtRegistry()->get(rg->getGID()).peerStorage_;
if(!ps.isNull()) { if(ps) {
std::vector<SharedHandle<Peer> > peers; std::vector<SharedHandle<Peer> > peers;
ps->getActivePeers(peers); ps->getActivePeers(peers);
o << " " << "SEED:" o << " " << "SEED:"
@ -280,7 +280,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
{ {
SharedHandle<FileAllocationEntry> entry = SharedHandle<FileAllocationEntry> entry =
e->getFileAllocationMan()->getPickedEntry(); e->getFileAllocationMan()->getPickedEntry();
if(!entry.isNull()) { if(entry) {
o << " " o << " "
<< "[FileAlloc:" << "[FileAlloc:"
<< "#" << entry->getRequestGroup()->getGID() << " " << "#" << entry->getRequestGroup()->getGID() << " "
@ -308,7 +308,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
{ {
SharedHandle<CheckIntegrityEntry> entry = SharedHandle<CheckIntegrityEntry> entry =
e->getCheckIntegrityMan()->getPickedEntry(); e->getCheckIntegrityMan()->getPickedEntry();
if(!entry.isNull()) { if(entry) {
o << " " o << " "
<< "[Checksum:" << "[Checksum:"
<< "#" << entry->getRequestGroup()->getGID() << " " << "#" << entry->getRequestGroup()->getGID() << " "

View file

@ -87,8 +87,8 @@ bool CreateRequestCommand::executeInternal()
getOption()->getAsBool(PREF_USE_HEAD)) || getOption()->getAsBool(PREF_USE_HEAD)) ||
getOption()->getAsBool(PREF_DRY_RUN)? getOption()->getAsBool(PREF_DRY_RUN)?
Request::METHOD_HEAD:Request::METHOD_GET)); Request::METHOD_HEAD:Request::METHOD_GET));
if(getRequest().isNull()) { if(!getRequest()) {
if(!getSegmentMan().isNull()) { if(getSegmentMan()) {
getSegmentMan()->ignoreSegmentFor(getFileEntry()); getSegmentMan()->ignoreSegmentFor(getFileEntry());
} }
throw DL_ABORT_EX("No URI available."); throw DL_ABORT_EX("No URI available.");

View file

@ -49,7 +49,12 @@ namespace aria2 {
DHTAbstractMessage::DHTAbstractMessage(const SharedHandle<DHTNode>& localNode, DHTAbstractMessage::DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode, const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID): const std::string& transactionID):
DHTMessage(localNode, remoteNode, transactionID) {} DHTMessage(localNode, remoteNode, transactionID),
connection_(0),
dispatcher_(0),
factory_(0),
routingTable_(0)
{}
DHTAbstractMessage::~DHTAbstractMessage() {} DHTAbstractMessage::~DHTAbstractMessage() {}
@ -75,26 +80,22 @@ bool DHTAbstractMessage::send()
return r == static_cast<ssize_t>(message.size()); return r == static_cast<ssize_t>(message.size());
} }
void DHTAbstractMessage::setConnection void DHTAbstractMessage::setConnection(DHTConnection* connection)
(const WeakHandle<DHTConnection>& connection)
{ {
connection_ = connection; connection_ = connection;
} }
void DHTAbstractMessage::setMessageDispatcher void DHTAbstractMessage::setMessageDispatcher(DHTMessageDispatcher* dispatcher)
(const WeakHandle<DHTMessageDispatcher>& dispatcher)
{ {
dispatcher_ = dispatcher; dispatcher_ = dispatcher;
} }
void DHTAbstractMessage::setMessageFactory void DHTAbstractMessage::setMessageFactory(DHTMessageFactory* factory)
(const WeakHandle<DHTMessageFactory>& factory)
{ {
factory_ = factory; factory_ = factory;
} }
void DHTAbstractMessage::setRoutingTable void DHTAbstractMessage::setRoutingTable(DHTRoutingTable* routingTable)
(const WeakHandle<DHTRoutingTable>& routingTable)
{ {
routingTable_ = routingTable; routingTable_ = routingTable;
} }

View file

@ -48,13 +48,13 @@ class DHTRoutingTable;
class DHTAbstractMessage:public DHTMessage { class DHTAbstractMessage:public DHTMessage {
private: private:
WeakHandle<DHTConnection> connection_; DHTConnection* connection_;
WeakHandle<DHTMessageDispatcher> dispatcher_; DHTMessageDispatcher* dispatcher_;
WeakHandle<DHTMessageFactory> factory_; DHTMessageFactory* factory_;
WeakHandle<DHTRoutingTable> routingTable_; DHTRoutingTable* routingTable_;
public: public:
DHTAbstractMessage(const SharedHandle<DHTNode>& localNode, DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode, const SharedHandle<DHTNode>& remoteNode,
@ -70,33 +70,33 @@ public:
std::string getBencodedMessage(); std::string getBencodedMessage();
const WeakHandle<DHTConnection>& getConnection() const DHTConnection* getConnection() const
{ {
return connection_; return connection_;
} }
void setConnection(const WeakHandle<DHTConnection>& connection); void setConnection(DHTConnection* connection);
const WeakHandle<DHTMessageDispatcher>& getMessageDispatcher() const DHTMessageDispatcher* getMessageDispatcher() const
{ {
return dispatcher_; return dispatcher_;
} }
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher>& dispatcher); void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
const WeakHandle<DHTMessageFactory>& getMessageFactory() const DHTMessageFactory* getMessageFactory() const
{ {
return factory_; return factory_;
} }
void setMessageFactory(const WeakHandle<DHTMessageFactory>& factory); void setMessageFactory(DHTMessageFactory* factory);
const WeakHandle<DHTRoutingTable>& getRoutingTable() const DHTRoutingTable* getRoutingTable() const
{ {
return routingTable_; return routingTable_;
} }
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable); void setRoutingTable(DHTRoutingTable* routingTable);
}; };
} // namespace aria2 } // namespace aria2

View file

@ -48,7 +48,11 @@ namespace aria2 {
DHTAbstractTask::DHTAbstractTask(): DHTAbstractTask::DHTAbstractTask():
finished_(false), finished_(false),
logger_(LogFactory::getInstance()) logger_(LogFactory::getInstance()),
routingTable_(0),
dispatcher_(0),
factory_(0),
taskQueue_(0)
{} {}
bool DHTAbstractTask::finished() bool DHTAbstractTask::finished()
@ -56,22 +60,22 @@ bool DHTAbstractTask::finished()
return finished_; return finished_;
} }
void DHTAbstractTask::setRoutingTable(const WeakHandle<DHTRoutingTable> routingTable) void DHTAbstractTask::setRoutingTable(DHTRoutingTable* routingTable)
{ {
routingTable_ = routingTable; routingTable_ = routingTable;
} }
void DHTAbstractTask::setMessageDispatcher(const WeakHandle<DHTMessageDispatcher> dispatcher) void DHTAbstractTask::setMessageDispatcher(DHTMessageDispatcher* dispatcher)
{ {
dispatcher_ = dispatcher; dispatcher_ = dispatcher;
} }
void DHTAbstractTask::setMessageFactory(const WeakHandle<DHTMessageFactory> factory) void DHTAbstractTask::setMessageFactory(DHTMessageFactory* factory)
{ {
factory_ = factory; factory_ = factory;
} }
void DHTAbstractTask::setTaskQueue(const WeakHandle<DHTTaskQueue> taskQueue) void DHTAbstractTask::setTaskQueue(DHTTaskQueue* taskQueue)
{ {
taskQueue_ = taskQueue; taskQueue_ = taskQueue;
} }

View file

@ -58,13 +58,13 @@ private:
SharedHandle<DHTNode> localNode_; SharedHandle<DHTNode> localNode_;
WeakHandle<DHTRoutingTable> routingTable_; DHTRoutingTable* routingTable_;
WeakHandle<DHTMessageDispatcher> dispatcher_; DHTMessageDispatcher* dispatcher_;
WeakHandle<DHTMessageFactory> factory_; DHTMessageFactory* factory_;
WeakHandle<DHTTaskQueue> taskQueue_; DHTTaskQueue* taskQueue_;
protected: protected:
void setFinished(bool f) void setFinished(bool f)
{ {
@ -80,33 +80,33 @@ public:
virtual bool finished(); virtual bool finished();
const WeakHandle<DHTRoutingTable>& getRoutingTable() const DHTRoutingTable* getRoutingTable() const
{ {
return routingTable_; return routingTable_;
} }
void setRoutingTable(const WeakHandle<DHTRoutingTable> routingTable); void setRoutingTable(DHTRoutingTable* routingTable);
const WeakHandle<DHTMessageDispatcher>& getMessageDispatcher() const DHTMessageDispatcher* getMessageDispatcher() const
{ {
return dispatcher_; return dispatcher_;
} }
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher> dispatcher); void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
const WeakHandle<DHTMessageFactory>& getMessageFactory() const DHTMessageFactory* getMessageFactory() const
{ {
return factory_; return factory_;
} }
void setMessageFactory(const WeakHandle<DHTMessageFactory> factory); void setMessageFactory(DHTMessageFactory* factory);
const WeakHandle<DHTTaskQueue>& getTaskQueue() const DHTTaskQueue* getTaskQueue() const
{ {
return taskQueue_; return taskQueue_;
} }
void setTaskQueue(const WeakHandle<DHTTaskQueue> taskQueue); void setTaskQueue(DHTTaskQueue* taskQueue);
const SharedHandle<DHTNode>& getLocalNode() const const SharedHandle<DHTNode>& getLocalNode() const
{ {

View file

@ -68,7 +68,9 @@ DHTAnnouncePeerMessage::DHTAnnouncePeerMessage
const std::string& transactionID): const std::string& transactionID):
DHTQueryMessage(localNode, remoteNode, transactionID), DHTQueryMessage(localNode, remoteNode, transactionID),
token_(token), token_(token),
tcpPort_(tcpPort) tcpPort_(tcpPort),
peerAnnounceStorage_(0),
tokenTracker_(0)
{ {
memcpy(infoHash_, infoHash, DHT_ID_LENGTH); memcpy(infoHash_, infoHash, DHT_ID_LENGTH);
} }
@ -115,13 +117,12 @@ void DHTAnnouncePeerMessage::validate() const
} }
void DHTAnnouncePeerMessage::setPeerAnnounceStorage void DHTAnnouncePeerMessage::setPeerAnnounceStorage
(const WeakHandle<DHTPeerAnnounceStorage>& storage) (DHTPeerAnnounceStorage* storage)
{ {
peerAnnounceStorage_ = storage; peerAnnounceStorage_ = storage;
} }
void DHTAnnouncePeerMessage::setTokenTracker void DHTAnnouncePeerMessage::setTokenTracker(DHTTokenTracker* tokenTracker)
(const WeakHandle<DHTTokenTracker>& tokenTracker)
{ {
tokenTracker_ = tokenTracker; tokenTracker_ = tokenTracker;
} }

View file

@ -52,9 +52,9 @@ private:
uint16_t tcpPort_; uint16_t tcpPort_;
WeakHandle<DHTPeerAnnounceStorage> peerAnnounceStorage_; DHTPeerAnnounceStorage* peerAnnounceStorage_;
WeakHandle<DHTTokenTracker> tokenTracker_; DHTTokenTracker* tokenTracker_;
protected: protected:
virtual std::string toStringOptional() const; virtual std::string toStringOptional() const;
public: public:
@ -90,9 +90,9 @@ public:
return tcpPort_; return tcpPort_;
} }
void setPeerAnnounceStorage(const WeakHandle<DHTPeerAnnounceStorage>& storage); void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage);
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker); void setTokenTracker(DHTTokenTracker* tokenTracker);
static const std::string ANNOUNCE_PEER; static const std::string ANNOUNCE_PEER;

View file

@ -80,7 +80,7 @@ bool DHTEntryPointNameResolveCommand::execute()
return true; return true;
} }
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
if(resolver_.isNull()) { if(!resolver_) {
int family; int family;
if(e_->getOption()->getAsBool(PREF_ENABLE_ASYNC_DNS6)) { if(e_->getOption()->getAsBool(PREF_ENABLE_ASYNC_DNS6)) {
family = AF_UNSPEC; family = AF_UNSPEC;

View file

@ -76,7 +76,7 @@ bool DHTGetPeersCommand::execute()
if(btRuntime_->isHalt()) { if(btRuntime_->isHalt()) {
return true; return true;
} }
if(task_.isNull() && if(!task_ &&
((numRetry_ > 0 && ((numRetry_ > 0 &&
lastGetPeerTime_.difference(global::wallclock) >= (time_t)numRetry_*5) || lastGetPeerTime_.difference(global::wallclock) >= (time_t)numRetry_*5) ||
lastGetPeerTime_.difference(global::wallclock) >= GET_PEER_INTERVAL || lastGetPeerTime_.difference(global::wallclock) >= GET_PEER_INTERVAL ||
@ -91,7 +91,7 @@ bool DHTGetPeersCommand::execute()
task_ = taskFactory_->createPeerLookupTask task_ = taskFactory_->createPeerLookupTask
(requestGroup_->getDownloadContext(), btRuntime_, peerStorage_); (requestGroup_->getDownloadContext(), btRuntime_, peerStorage_);
taskQueue_->addPeriodicTask2(task_); taskQueue_->addPeriodicTask2(task_);
} else if(!task_.isNull() && task_->finished()) { } else if(task_ && task_->finished()) {
lastGetPeerTime_ = global::wallclock; lastGetPeerTime_ = global::wallclock;
if(numRetry_ < MAX_RETRIES && btRuntime_->lessThanMinPeers()) { if(numRetry_ < MAX_RETRIES && btRuntime_->lessThanMinPeers()) {
++numRetry_; ++numRetry_;

View file

@ -56,7 +56,9 @@ DHTGetPeersMessage::DHTGetPeersMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode, const SharedHandle<DHTNode>& remoteNode,
const unsigned char* infoHash, const unsigned char* infoHash,
const std::string& transactionID): const std::string& transactionID):
DHTQueryMessage(localNode, remoteNode, transactionID) DHTQueryMessage(localNode, remoteNode, transactionID),
peerAnnounceStorage_(0),
tokenTracker_(0)
{ {
memcpy(infoHash_, infoHash, DHT_ID_LENGTH); memcpy(infoHash_, infoHash, DHT_ID_LENGTH);
} }
@ -91,14 +93,12 @@ const std::string& DHTGetPeersMessage::getMessageType() const
return GET_PEERS; return GET_PEERS;
} }
void DHTGetPeersMessage::setPeerAnnounceStorage void DHTGetPeersMessage::setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage)
(const WeakHandle<DHTPeerAnnounceStorage>& storage)
{ {
peerAnnounceStorage_ = storage; peerAnnounceStorage_ = storage;
} }
void DHTGetPeersMessage::setTokenTracker void DHTGetPeersMessage::setTokenTracker(DHTTokenTracker* tokenTracker)
(const WeakHandle<DHTTokenTracker>& tokenTracker)
{ {
tokenTracker_ = tokenTracker; tokenTracker_ = tokenTracker;
} }

View file

@ -48,9 +48,9 @@ class DHTGetPeersMessage:public DHTQueryMessage {
private: private:
unsigned char infoHash_[DHT_ID_LENGTH]; unsigned char infoHash_[DHT_ID_LENGTH];
WeakHandle<DHTPeerAnnounceStorage> peerAnnounceStorage_; DHTPeerAnnounceStorage* peerAnnounceStorage_;
WeakHandle<DHTTokenTracker> tokenTracker_; DHTTokenTracker* tokenTracker_;
protected: protected:
virtual std::string toStringOptional() const; virtual std::string toStringOptional() const;
public: public:
@ -72,10 +72,9 @@ public:
return infoHash_; return infoHash_;
} }
void setPeerAnnounceStorage void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage);
(const WeakHandle<DHTPeerAnnounceStorage>& storage);
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker); void setTokenTracker(DHTTokenTracker* tokenTracker);
static const std::string GET_PEERS; static const std::string GET_PEERS;

View file

@ -82,7 +82,7 @@ bool DHTInteractionCommand::execute()
for(size_t i = 0; i < 20; ++i) { for(size_t i = 0; i < 20; ++i) {
SharedHandle<DHTMessage> m = receiver_->receiveMessage(); SharedHandle<DHTMessage> m = receiver_->receiveMessage();
if(m.isNull()) { if(!m) {
break; break;
} }
} }

View file

@ -66,6 +66,11 @@ namespace aria2 {
DHTMessageFactoryImpl::DHTMessageFactoryImpl(int family): DHTMessageFactoryImpl::DHTMessageFactoryImpl(int family):
family_(family), family_(family),
connection_(0),
dispatcher_(0),
routingTable_(0),
peerAnnounceStorage_(0),
tokenTracker_(0),
logger_(LogFactory::getInstance()) {} logger_(LogFactory::getInstance()) {}
DHTMessageFactoryImpl::~DHTMessageFactoryImpl() {} DHTMessageFactoryImpl::~DHTMessageFactoryImpl() {}
@ -75,7 +80,7 @@ DHTMessageFactoryImpl::getRemoteNode
(const unsigned char* id, const std::string& ipaddr, uint16_t port) const (const unsigned char* id, const std::string& ipaddr, uint16_t port) const
{ {
SharedHandle<DHTNode> node = routingTable_->getNode(id, ipaddr, port); SharedHandle<DHTNode> node = routingTable_->getNode(id, ipaddr, port);
if(node.isNull()) { if(!node) {
node.reset(new DHTNode(id)); node.reset(new DHTNode(id));
node->setIPAddress(ipaddr); node->setIPAddress(ipaddr);
node->setPort(port); node->setPort(port);
@ -309,8 +314,7 @@ void DHTMessageFactoryImpl::setCommonProperty
m->setConnection(connection_); m->setConnection(connection_);
m->setMessageDispatcher(dispatcher_); m->setMessageDispatcher(dispatcher_);
m->setRoutingTable(routingTable_); m->setRoutingTable(routingTable_);
WeakHandle<DHTMessageFactory> factory(this); m->setMessageFactory(this);
m->setMessageFactory(factory);
m->setVersion(getDefaultVersion()); m->setVersion(getDefaultVersion());
} }
@ -506,32 +510,29 @@ DHTMessageFactoryImpl::createUnknownMessage
return m; return m;
} }
void DHTMessageFactoryImpl::setRoutingTable void DHTMessageFactoryImpl::setRoutingTable(DHTRoutingTable* routingTable)
(const WeakHandle<DHTRoutingTable>& routingTable)
{ {
routingTable_ = routingTable; routingTable_ = routingTable;
} }
void DHTMessageFactoryImpl::setConnection void DHTMessageFactoryImpl::setConnection(DHTConnection* connection)
(const WeakHandle<DHTConnection>& connection)
{ {
connection_ = connection; connection_ = connection;
} }
void DHTMessageFactoryImpl::setMessageDispatcher void DHTMessageFactoryImpl::setMessageDispatcher
(const WeakHandle<DHTMessageDispatcher>& dispatcher) (DHTMessageDispatcher* dispatcher)
{ {
dispatcher_ = dispatcher; dispatcher_ = dispatcher;
} }
void DHTMessageFactoryImpl::setPeerAnnounceStorage void DHTMessageFactoryImpl::setPeerAnnounceStorage
(const WeakHandle<DHTPeerAnnounceStorage>& storage) (DHTPeerAnnounceStorage* storage)
{ {
peerAnnounceStorage_ = storage; peerAnnounceStorage_ = storage;
} }
void DHTMessageFactoryImpl::setTokenTracker void DHTMessageFactoryImpl::setTokenTracker(DHTTokenTracker* tokenTracker)
(const WeakHandle<DHTTokenTracker>& tokenTracker)
{ {
tokenTracker_ = tokenTracker; tokenTracker_ = tokenTracker;
} }

View file

@ -55,15 +55,15 @@ private:
SharedHandle<DHTNode> localNode_; SharedHandle<DHTNode> localNode_;
WeakHandle<DHTConnection> connection_; DHTConnection* connection_;
WeakHandle<DHTMessageDispatcher> dispatcher_; DHTMessageDispatcher* dispatcher_;
WeakHandle<DHTRoutingTable> routingTable_; DHTRoutingTable* routingTable_;
WeakHandle<DHTPeerAnnounceStorage> peerAnnounceStorage_; DHTPeerAnnounceStorage* peerAnnounceStorage_;
WeakHandle<DHTTokenTracker> tokenTracker_; DHTTokenTracker* tokenTracker_;
Logger* logger_; Logger* logger_;
@ -155,16 +155,15 @@ public:
createUnknownMessage(const unsigned char* data, size_t length, createUnknownMessage(const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port); const std::string& ipaddr, uint16_t port);
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable); void setRoutingTable(DHTRoutingTable* routingTable);
void setConnection(const WeakHandle<DHTConnection>& connection); void setConnection(DHTConnection* connection);
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher>& dispatcher); void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
void setPeerAnnounceStorage void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage);
(const WeakHandle<DHTPeerAnnounceStorage>& storage);
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker); void setTokenTracker(DHTTokenTracker* tokenTracker);
void setLocalNode(const SharedHandle<DHTNode>& localNode); void setLocalNode(const SharedHandle<DHTNode>& localNode);
}; };

View file

@ -97,12 +97,12 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
std::pair<SharedHandle<DHTResponseMessage>, std::pair<SharedHandle<DHTResponseMessage>,
SharedHandle<DHTMessageCallback> > p = SharedHandle<DHTMessageCallback> > p =
tracker_->messageArrived(dict, remoteAddr, remotePort); tracker_->messageArrived(dict, remoteAddr, remotePort);
if(p.first.isNull()) { if(!p.first) {
// timeout or malicious? message // timeout or malicious? message
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort); return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
} }
onMessageReceived(p.first); onMessageReceived(p.first);
if(!p.second.isNull()) { if(p.second) {
p.second->onReceived(p.first); p.second->onReceived(p.first);
} }
return p.first; return p.first;

View file

@ -129,7 +129,7 @@ void DHTMessageTracker::handleTimeoutEntry
routingTable_->dropNode(node); routingTable_->dropNode(node);
} }
SharedHandle<DHTMessageCallback> callback = entry->getCallback(); SharedHandle<DHTMessageCallback> callback = entry->getCallback();
if(!callback.isNull()) { if(callback) {
callback->onTimeout(node); callback->onTimeout(node);
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {

View file

@ -41,7 +41,7 @@ DHTNodeLookupEntry::DHTNodeLookupEntry(const SharedHandle<DHTNode>& node):
node(node), used(false) {} node(node), used(false) {}
DHTNodeLookupEntry::DHTNodeLookupEntry(): DHTNodeLookupEntry::DHTNodeLookupEntry():
node(0), used(false) {} used(false) {}
bool DHTNodeLookupEntry::operator==(const DHTNodeLookupEntry& entry) const bool DHTNodeLookupEntry::operator==(const DHTNodeLookupEntry& entry) const
{ {

View file

@ -62,7 +62,7 @@ void DHTReplaceNodeTask::startup()
void DHTReplaceNodeTask::sendMessage() void DHTReplaceNodeTask::sendMessage()
{ {
SharedHandle<DHTNode> questionableNode = bucket_->getLRUQuestionableNode(); SharedHandle<DHTNode> questionableNode = bucket_->getLRUQuestionableNode();
if(questionableNode.isNull()) { if(!questionableNode) {
setFinished(true); setFinished(true);
} else { } else {
SharedHandle<DHTMessage> m = SharedHandle<DHTMessage> m =

View file

@ -115,7 +115,7 @@ void DHTSetup::setup
logger_->error("Exception caught while loading DHT routing table from %s", logger_->error("Exception caught while loading DHT routing table from %s",
e, dhtFile.c_str()); e, dhtFile.c_str());
} }
if(localNode.isNull()) { if(!localNode) {
localNode.reset(new DHTNode()); localNode.reset(new DHTNode());
} }
@ -167,10 +167,10 @@ void DHTSetup::setup
receiver->setRoutingTable(routingTable); receiver->setRoutingTable(routingTable);
taskFactory->setLocalNode(localNode); taskFactory->setLocalNode(localNode);
taskFactory->setRoutingTable(routingTable); taskFactory->setRoutingTable(routingTable.get());
taskFactory->setMessageDispatcher(dispatcher); taskFactory->setMessageDispatcher(dispatcher.get());
taskFactory->setMessageFactory(factory); taskFactory->setMessageFactory(factory.get());
taskFactory->setTaskQueue(taskQueue); taskFactory->setTaskQueue(taskQueue.get());
taskFactory->setTimeout(messageTimeout); taskFactory->setTimeout(messageTimeout);
routingTable->setTaskQueue(taskQueue); routingTable->setTaskQueue(taskQueue);
@ -179,11 +179,11 @@ void DHTSetup::setup
peerAnnounceStorage->setTaskQueue(taskQueue); peerAnnounceStorage->setTaskQueue(taskQueue);
peerAnnounceStorage->setTaskFactory(taskFactory); peerAnnounceStorage->setTaskFactory(taskFactory);
factory->setRoutingTable(routingTable); factory->setRoutingTable(routingTable.get());
factory->setConnection(connection); factory->setConnection(connection.get());
factory->setMessageDispatcher(dispatcher); factory->setMessageDispatcher(dispatcher.get());
factory->setPeerAnnounceStorage(peerAnnounceStorage); factory->setPeerAnnounceStorage(peerAnnounceStorage.get());
factory->setTokenTracker(tokenTracker); factory->setTokenTracker(tokenTracker.get());
factory->setLocalNode(localNode); factory->setLocalNode(localNode);
// assign them into DHTRegistry // assign them into DHTRegistry

View file

@ -54,6 +54,10 @@
namespace aria2 { namespace aria2 {
DHTTaskFactoryImpl::DHTTaskFactoryImpl(): DHTTaskFactoryImpl::DHTTaskFactoryImpl():
routingTable_(0),
dispatcher_(0),
factory_(0),
taskQueue_(0),
timeout_(DHT_MESSAGE_TIMEOUT), timeout_(DHT_MESSAGE_TIMEOUT),
logger_(LogFactory::getInstance()) {} logger_(LogFactory::getInstance()) {}
@ -125,22 +129,22 @@ void DHTTaskFactoryImpl::setCommonProperty(const SharedHandle<DHTAbstractTask>&
task->setLocalNode(localNode_); task->setLocalNode(localNode_);
} }
void DHTTaskFactoryImpl::setRoutingTable(const WeakHandle<DHTRoutingTable> routingTable) void DHTTaskFactoryImpl::setRoutingTable(DHTRoutingTable* routingTable)
{ {
routingTable_ = routingTable; routingTable_ = routingTable;
} }
void DHTTaskFactoryImpl::setMessageDispatcher(const WeakHandle<DHTMessageDispatcher> dispatcher) void DHTTaskFactoryImpl::setMessageDispatcher(DHTMessageDispatcher* dispatcher)
{ {
dispatcher_ = dispatcher; dispatcher_ = dispatcher;
} }
void DHTTaskFactoryImpl::setMessageFactory(const WeakHandle<DHTMessageFactory> factory) void DHTTaskFactoryImpl::setMessageFactory(DHTMessageFactory* factory)
{ {
factory_ = factory; factory_ = factory;
} }
void DHTTaskFactoryImpl::setTaskQueue(const WeakHandle<DHTTaskQueue> taskQueue) void DHTTaskFactoryImpl::setTaskQueue(DHTTaskQueue* taskQueue)
{ {
taskQueue_ = taskQueue; taskQueue_ = taskQueue;
} }

View file

@ -52,13 +52,13 @@ class DHTTaskFactoryImpl:public DHTTaskFactory {
private: private:
SharedHandle<DHTNode> localNode_; SharedHandle<DHTNode> localNode_;
WeakHandle<DHTRoutingTable> routingTable_; DHTRoutingTable* routingTable_;
WeakHandle<DHTMessageDispatcher> dispatcher_; DHTMessageDispatcher* dispatcher_;
WeakHandle<DHTMessageFactory> factory_; DHTMessageFactory* factory_;
WeakHandle<DHTTaskQueue> taskQueue_; DHTTaskQueue* taskQueue_;
time_t timeout_; time_t timeout_;
@ -91,13 +91,13 @@ public:
createReplaceNodeTask(const SharedHandle<DHTBucket>& bucket, createReplaceNodeTask(const SharedHandle<DHTBucket>& bucket,
const SharedHandle<DHTNode>& newNode); const SharedHandle<DHTNode>& newNode);
void setRoutingTable(const WeakHandle<DHTRoutingTable> routingTable); void setRoutingTable(DHTRoutingTable* routingTable);
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher> dispatcher); void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
void setMessageFactory(const WeakHandle<DHTMessageFactory> factory); void setMessageFactory(DHTMessageFactory* factory);
void setTaskQueue(const WeakHandle<DHTTaskQueue> taskQueue); void setTaskQueue(DHTTaskQueue* taskQueue);
void setLocalNode(const SharedHandle<DHTNode>& localNode); void setLocalNode(const SharedHandle<DHTNode>& localNode);

View file

@ -40,7 +40,7 @@ namespace aria2 {
AuthConfigHandle DefaultAuthResolver::resolveAuthConfig AuthConfigHandle DefaultAuthResolver::resolveAuthConfig
(const std::string& hostname) (const std::string& hostname)
{ {
if(getUserDefinedAuthConfig().isNull()) { if(!getUserDefinedAuthConfig()) {
return getDefaultAuthConfig(); return getDefaultAuthConfig();
} else { } else {
return getUserDefinedAuthConfig(); return getUserDefinedAuthConfig();

View file

@ -276,7 +276,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
} }
} }
const SharedHandle<ValueBase>& peerData = dict->get(BtAnnounce::PEERS); const SharedHandle<ValueBase>& peerData = dict->get(BtAnnounce::PEERS);
if(peerData.isNull()) { if(!peerData) {
logger_->info(MSG_NO_PEER_LIST_RECEIVED); logger_->info(MSG_NO_PEER_LIST_RECEIVED);
} else { } else {
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) { if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {
@ -286,7 +286,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
} }
} }
const SharedHandle<ValueBase>& peer6Data = dict->get(BtAnnounce::PEERS6); const SharedHandle<ValueBase>& peer6Data = dict->get(BtAnnounce::PEERS6);
if(peer6Data.isNull()) { if(!peer6Data) {
logger_->info("No peers6 received."); logger_->info("No peers6 received.");
} else { } else {
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) { if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {

View file

@ -83,6 +83,7 @@ DefaultBtInteractive::DefaultBtInteractive
downloadContext_(downloadContext), downloadContext_(downloadContext),
peer_(peer), peer_(peer),
metadataGetMode_(false), metadataGetMode_(false),
localNode_(0),
logger_(LogFactory::getInstance()), logger_(LogFactory::getInstance()),
allowedFastSetSize_(10), allowedFastSetSize_(10),
haveTimer_(global::wallclock), haveTimer_(global::wallclock),
@ -95,7 +96,8 @@ DefaultBtInteractive::DefaultBtInteractive
utPexEnabled_(false), utPexEnabled_(false),
dhtEnabled_(false), dhtEnabled_(false),
numReceivedMessage_(0), numReceivedMessage_(0),
maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST) maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST),
requestGroupMan_(0)
{} {}
DefaultBtInteractive::~DefaultBtInteractive() {} DefaultBtInteractive::~DefaultBtInteractive() {}
@ -111,7 +113,7 @@ void DefaultBtInteractive::initiateHandshake() {
BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) { BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
SharedHandle<BtHandshakeMessage> message = SharedHandle<BtHandshakeMessage> message =
btMessageReceiver_->receiveHandshake(quickReply); btMessageReceiver_->receiveHandshake(quickReply);
if(message.isNull()) { if(!message) {
return SharedHandle<BtMessage>(); return SharedHandle<BtMessage>();
} }
if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(), if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(),
@ -290,7 +292,7 @@ size_t DefaultBtInteractive::receiveMessages() {
break; break;
} }
BtMessageHandle message = btMessageReceiver_->receiveMessage(); BtMessageHandle message = btMessageReceiver_->receiveMessage();
if(message.isNull()) { if(!message) {
break; break;
} }
++msgcount; ++msgcount;
@ -569,7 +571,7 @@ void DefaultBtInteractive::doInteractionProcessing() {
sendPendingMessage(); sendPendingMessage();
} }
void DefaultBtInteractive::setLocalNode(const WeakHandle<DHTNode>& node) void DefaultBtInteractive::setLocalNode(DHTNode* node)
{ {
localNode_ = node; localNode_ = node;
} }
@ -657,8 +659,7 @@ void DefaultBtInteractive::setBtMessageFactory
messageFactory_ = factory; messageFactory_ = factory;
} }
void DefaultBtInteractive::setRequestGroupMan void DefaultBtInteractive::setRequestGroupMan(RequestGroupMan* rgman)
(const WeakHandle<RequestGroupMan>& rgman)
{ {
requestGroupMan_ = rgman; requestGroupMan_ = rgman;
} }

View file

@ -124,7 +124,7 @@ private:
bool metadataGetMode_; bool metadataGetMode_;
WeakHandle<DHTNode> localNode_; DHTNode* localNode_;
Logger* logger_; Logger* logger_;
size_t allowedFastSetSize_; size_t allowedFastSetSize_;
@ -143,7 +143,7 @@ private:
size_t maxOutstandingRequest_; size_t maxOutstandingRequest_;
WeakHandle<RequestGroupMan> requestGroupMan_; RequestGroupMan* requestGroupMan_;
static const time_t FLOODING_CHECK_INTERVAL = 5; static const time_t FLOODING_CHECK_INTERVAL = 5;
@ -232,14 +232,14 @@ public:
utPexEnabled_ = f; utPexEnabled_ = f;
} }
void setLocalNode(const WeakHandle<DHTNode>& node); void setLocalNode(DHTNode* node);
void setDHTEnabled(bool f) void setDHTEnabled(bool f)
{ {
dhtEnabled_ = f; dhtEnabled_ = f;
} }
void setRequestGroupMan(const WeakHandle<RequestGroupMan>& rgman); void setRequestGroupMan(RequestGroupMan* rgman);
void setUTMetadataRequestTracker void setUTMetadataRequestTracker
(const SharedHandle<UTMetadataRequestTracker>& tracker) (const SharedHandle<UTMetadataRequestTracker>& tracker)

View file

@ -60,6 +60,8 @@ namespace aria2 {
DefaultBtMessageDispatcher::DefaultBtMessageDispatcher(): DefaultBtMessageDispatcher::DefaultBtMessageDispatcher():
cuid(0), cuid(0),
messageFactory_(0),
requestGroupMan_(0),
requestTimeout_(0), requestTimeout_(0),
logger_(LogFactory::getInstance()) {} logger_(LogFactory::getInstance()) {}
@ -266,14 +268,14 @@ private:
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;
SharedHandle<PieceStorage> pieceStorage_; SharedHandle<PieceStorage> pieceStorage_;
BtMessageDispatcher* messageDispatcher_; BtMessageDispatcher* messageDispatcher_;
WeakHandle<BtMessageFactory> messageFactory_; BtMessageFactory* messageFactory_;
time_t requestTimeout_; time_t requestTimeout_;
Logger* logger_; Logger* logger_;
public: public:
ProcessStaleRequestSlot(cuid_t cuid, const SharedHandle<Peer>& peer, ProcessStaleRequestSlot(cuid_t cuid, const SharedHandle<Peer>& peer,
const SharedHandle<PieceStorage>& pieceStorage, const SharedHandle<PieceStorage>& pieceStorage,
BtMessageDispatcher* dispatcher, BtMessageDispatcher* dispatcher,
const WeakHandle<BtMessageFactory>& factory, BtMessageFactory* factory,
time_t requestTimeout): time_t requestTimeout):
cuid_(cuid), cuid_(cuid),
peer_(peer), peer_(peer),
@ -453,14 +455,12 @@ void DefaultBtMessageDispatcher::setPeerStorage
peerStorage_ = peerStorage; peerStorage_ = peerStorage;
} }
void DefaultBtMessageDispatcher::setBtMessageFactory void DefaultBtMessageDispatcher::setBtMessageFactory(BtMessageFactory* factory)
(const WeakHandle<BtMessageFactory>& factory)
{ {
messageFactory_ = factory; messageFactory_ = factory;
} }
void DefaultBtMessageDispatcher::setRequestGroupMan void DefaultBtMessageDispatcher::setRequestGroupMan(RequestGroupMan* rgman)
(const WeakHandle<RequestGroupMan>& rgman)
{ {
requestGroupMan_ = rgman; requestGroupMan_ = rgman;
} }

View file

@ -62,9 +62,9 @@ private:
SharedHandle<DownloadContext> downloadContext_; SharedHandle<DownloadContext> downloadContext_;
SharedHandle<PeerStorage> peerStorage_; SharedHandle<PeerStorage> peerStorage_;
SharedHandle<PieceStorage> pieceStorage_; SharedHandle<PieceStorage> pieceStorage_;
WeakHandle<BtMessageFactory> messageFactory_; BtMessageFactory* messageFactory_;
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;
WeakHandle<RequestGroupMan> requestGroupMan_; RequestGroupMan* requestGroupMan_;
time_t requestTimeout_; time_t requestTimeout_;
Logger* logger_; Logger* logger_;
public: public:
@ -130,9 +130,9 @@ public:
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage); void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory); void setBtMessageFactory(BtMessageFactory* factory);
void setRequestGroupMan(const WeakHandle<RequestGroupMan>& rgman); void setRequestGroupMan(RequestGroupMan* rgman);
void setCuid(cuid_t cuid) void setCuid(cuid_t cuid)
{ {

View file

@ -70,9 +70,17 @@
namespace aria2 { namespace aria2 {
DefaultBtMessageFactory::DefaultBtMessageFactory():cuid_(0), DefaultBtMessageFactory::DefaultBtMessageFactory():
dhtEnabled_(false), cuid_(0),
metadataGetMode_(false) dhtEnabled_(false),
dispatcher_(0),
requestFactory_(0),
peerConnection_(0),
localNode_(0),
routingTable_(0),
taskQueue_(0),
taskFactory_(0),
metadataGetMode_(false)
{} {}
DefaultBtMessageFactory::~DefaultBtMessageFactory() {} DefaultBtMessageFactory::~DefaultBtMessageFactory() {}
@ -251,7 +259,7 @@ void DefaultBtMessageFactory::setCommonProperty
msg->setPieceStorage(pieceStorage_); msg->setPieceStorage(pieceStorage_);
msg->setBtMessageDispatcher(dispatcher_); msg->setBtMessageDispatcher(dispatcher_);
msg->setBtRequestFactory(requestFactory_); msg->setBtRequestFactory(requestFactory_);
msg->setBtMessageFactory(WeakHandle<BtMessageFactory>(this)); msg->setBtMessageFactory(this);
msg->setPeerConnection(peerConnection_); msg->setPeerConnection(peerConnection_);
if(metadataGetMode_) { if(metadataGetMode_) {
msg->enableMetadataGetMode(); msg->enableMetadataGetMode();
@ -460,14 +468,12 @@ DefaultBtMessageFactory::createBtExtendedMessage
return m; return m;
} }
void DefaultBtMessageFactory::setTaskQueue void DefaultBtMessageFactory::setTaskQueue(DHTTaskQueue* taskQueue)
(const WeakHandle<DHTTaskQueue>& taskQueue)
{ {
taskQueue_ = taskQueue; taskQueue_ = taskQueue;
} }
void DefaultBtMessageFactory::setTaskFactory void DefaultBtMessageFactory::setTaskFactory(DHTTaskFactory* taskFactory)
(const WeakHandle<DHTTaskFactory>& taskFactory)
{ {
taskFactory_ = taskFactory; taskFactory_ = taskFactory;
} }
@ -496,7 +502,7 @@ void DefaultBtMessageFactory::setPeerStorage
} }
void DefaultBtMessageFactory::setBtMessageDispatcher void DefaultBtMessageFactory::setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher) (BtMessageDispatcher* dispatcher)
{ {
dispatcher_ = dispatcher; dispatcher_ = dispatcher;
} }
@ -507,25 +513,22 @@ void DefaultBtMessageFactory::setExtensionMessageFactory
extensionMessageFactory_ = factory; extensionMessageFactory_ = factory;
} }
void DefaultBtMessageFactory::setLocalNode(const WeakHandle<DHTNode>& localNode) void DefaultBtMessageFactory::setLocalNode(DHTNode* localNode)
{ {
localNode_ = localNode; localNode_ = localNode;
} }
void DefaultBtMessageFactory::setRoutingTable void DefaultBtMessageFactory::setRoutingTable(DHTRoutingTable* routingTable)
(const WeakHandle<DHTRoutingTable>& routingTable)
{ {
routingTable_ = routingTable; routingTable_ = routingTable;
} }
void DefaultBtMessageFactory::setBtRequestFactory void DefaultBtMessageFactory::setBtRequestFactory(BtRequestFactory* factory)
(const WeakHandle<BtRequestFactory>& factory)
{ {
requestFactory_ = factory; requestFactory_ = factory;
} }
void DefaultBtMessageFactory::setPeerConnection void DefaultBtMessageFactory::setPeerConnection(PeerConnection* connection)
(const WeakHandle<PeerConnection>& connection)
{ {
peerConnection_ = connection; peerConnection_ = connection;
} }

View file

@ -64,21 +64,21 @@ private:
bool dhtEnabled_; bool dhtEnabled_;
WeakHandle<BtMessageDispatcher> dispatcher_; BtMessageDispatcher* dispatcher_;
WeakHandle<BtRequestFactory> requestFactory_; BtRequestFactory* requestFactory_;
WeakHandle<PeerConnection> peerConnection_; PeerConnection* peerConnection_;
SharedHandle<ExtensionMessageFactory> extensionMessageFactory_; SharedHandle<ExtensionMessageFactory> extensionMessageFactory_;
DHTNode* localNode_;
WeakHandle<DHTNode> localNode_; DHTRoutingTable* routingTable_;
WeakHandle<DHTRoutingTable> routingTable_; DHTTaskQueue* taskQueue_;
WeakHandle<DHTTaskQueue> taskQueue_; DHTTaskFactory* taskFactory_;
WeakHandle<DHTTaskFactory> taskFactory_;
bool metadataGetMode_; bool metadataGetMode_;
@ -153,22 +153,22 @@ public:
} }
void setBtMessageDispatcher void setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher); (BtMessageDispatcher* dispatcher);
void setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory); void setBtRequestFactory(BtRequestFactory* factory);
void setPeerConnection(const WeakHandle<PeerConnection>& connection); void setPeerConnection(PeerConnection* connection);
void setExtensionMessageFactory void setExtensionMessageFactory
(const SharedHandle<ExtensionMessageFactory>& factory); (const SharedHandle<ExtensionMessageFactory>& factory);
void setLocalNode(const WeakHandle<DHTNode>& localNode); void setLocalNode(DHTNode* localNode);
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable); void setRoutingTable(DHTRoutingTable* routingTable);
void setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue); void setTaskQueue(DHTTaskQueue* taskQueue);
void setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory); void setTaskFactory(DHTTaskFactory* taskFactory);
void enableMetadataGetMode() void enableMetadataGetMode()
{ {

View file

@ -51,7 +51,10 @@
namespace aria2 { namespace aria2 {
DefaultBtMessageReceiver::DefaultBtMessageReceiver(): DefaultBtMessageReceiver::DefaultBtMessageReceiver():
handshakeSent_(false) handshakeSent_(false),
peerConnection_(0),
dispatcher_(0),
messageFactory_(0)
{} {}
SharedHandle<BtHandshakeMessage> SharedHandle<BtHandshakeMessage>
@ -115,20 +118,17 @@ void DefaultBtMessageReceiver::setDownloadContext
downloadContext_ = downloadContext; downloadContext_ = downloadContext;
} }
void DefaultBtMessageReceiver::setPeerConnection void DefaultBtMessageReceiver::setPeerConnection(PeerConnection* peerConnection)
(const WeakHandle<PeerConnection>& peerConnection)
{ {
peerConnection_ = peerConnection; peerConnection_ = peerConnection;
} }
void DefaultBtMessageReceiver::setDispatcher void DefaultBtMessageReceiver::setDispatcher(BtMessageDispatcher* dispatcher)
(const WeakHandle<BtMessageDispatcher>& dispatcher)
{ {
dispatcher_ = dispatcher; dispatcher_ = dispatcher;
} }
void DefaultBtMessageReceiver::setBtMessageFactory void DefaultBtMessageReceiver::setBtMessageFactory(BtMessageFactory* factory)
(const WeakHandle<BtMessageFactory>& factory)
{ {
messageFactory_ = factory; messageFactory_ = factory;
} }

View file

@ -51,9 +51,9 @@ class DefaultBtMessageReceiver : public BtMessageReceiver {
private: private:
bool handshakeSent_; bool handshakeSent_;
SharedHandle<DownloadContext> downloadContext_; SharedHandle<DownloadContext> downloadContext_;
WeakHandle<PeerConnection> peerConnection_; PeerConnection* peerConnection_;
WeakHandle<BtMessageDispatcher> dispatcher_; BtMessageDispatcher* dispatcher_;
WeakHandle<BtMessageFactory> messageFactory_; BtMessageFactory* messageFactory_;
void sendHandshake(); void sendHandshake();
public: public:
@ -68,11 +68,11 @@ public:
void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext); void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
void setPeerConnection(const WeakHandle<PeerConnection>& peerConnection); void setPeerConnection(PeerConnection* peerConnection);
void setDispatcher(const WeakHandle<BtMessageDispatcher>& dispatcher); void setDispatcher(BtMessageDispatcher* dispatcher);
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory); void setBtMessageFactory(BtMessageFactory* factory);
}; };
typedef SharedHandle<DefaultBtMessageReceiver> DefaultBtMessageReceiverHandle; typedef SharedHandle<DefaultBtMessageReceiver> DefaultBtMessageReceiverHandle;

View file

@ -96,7 +96,7 @@ void DefaultBtProgressInfoFile::updateFilename()
bool DefaultBtProgressInfoFile::isTorrentDownload() bool DefaultBtProgressInfoFile::isTorrentDownload()
{ {
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
return !btRuntime_.isNull(); return btRuntime_;
#else // !ENABLE_BITTORRENT #else // !ENABLE_BITTORRENT
return false; return false;
#endif // !ENABLE_BITTORRENT #endif // !ENABLE_BITTORRENT

View file

@ -51,6 +51,8 @@
namespace aria2 { namespace aria2 {
DefaultBtRequestFactory::DefaultBtRequestFactory(): DefaultBtRequestFactory::DefaultBtRequestFactory():
dispatcher_(0),
messageFactory_(0),
logger_(LogFactory::getInstance()) logger_(LogFactory::getInstance())
{ {
if(logger_->debug()) { if(logger_->debug()) {
@ -74,9 +76,9 @@ namespace {
class AbortCompletedPieceRequest class AbortCompletedPieceRequest
{ {
private: private:
WeakHandle<BtMessageDispatcher> dispatcher_; BtMessageDispatcher* dispatcher_;
public: public:
AbortCompletedPieceRequest(const WeakHandle<BtMessageDispatcher>& dispatcher): AbortCompletedPieceRequest(BtMessageDispatcher* dispatcher):
dispatcher_(dispatcher) {} dispatcher_(dispatcher) {}
void operator()(const SharedHandle<Piece>& piece) void operator()(const SharedHandle<Piece>& piece)
@ -110,10 +112,10 @@ namespace {
class ProcessChokedPiece { class ProcessChokedPiece {
private: private:
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;
WeakHandle<PieceStorage> pieceStorage_; SharedHandle<PieceStorage> pieceStorage_;
public: public:
ProcessChokedPiece(const SharedHandle<Peer>& peer, ProcessChokedPiece(const SharedHandle<Peer>& peer,
const WeakHandle<PieceStorage>& pieceStorage): const SharedHandle<PieceStorage>& pieceStorage):
peer_(peer), peer_(peer),
pieceStorage_(pieceStorage) {} pieceStorage_(pieceStorage) {}
@ -280,13 +282,12 @@ void DefaultBtRequestFactory::setPeer(const SharedHandle<Peer>& peer)
} }
void DefaultBtRequestFactory::setBtMessageDispatcher void DefaultBtRequestFactory::setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher) (BtMessageDispatcher* dispatcher)
{ {
dispatcher_ = dispatcher; dispatcher_ = dispatcher;
} }
void DefaultBtRequestFactory::setBtMessageFactory void DefaultBtRequestFactory::setBtMessageFactory(BtMessageFactory* factory)
(const WeakHandle<BtMessageFactory>& factory)
{ {
messageFactory_ = factory; messageFactory_ = factory;
} }

View file

@ -54,8 +54,8 @@ class DefaultBtRequestFactory : public BtRequestFactory {
private: private:
SharedHandle<PieceStorage> pieceStorage_; SharedHandle<PieceStorage> pieceStorage_;
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;
WeakHandle<BtMessageDispatcher> dispatcher_; BtMessageDispatcher* dispatcher_;
WeakHandle<BtMessageFactory> messageFactory_; BtMessageFactory* messageFactory_;
std::deque<SharedHandle<Piece> > pieces_; std::deque<SharedHandle<Piece> > pieces_;
Logger* logger_; Logger* logger_;
public: public:
@ -96,10 +96,9 @@ public:
void setPeer(const SharedHandle<Peer>& peer); void setPeer(const SharedHandle<Peer>& peer);
void setBtMessageDispatcher void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
(const WeakHandle<BtMessageDispatcher>& dispatcher);
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory); void setBtMessageFactory(BtMessageFactory* factory);
}; };
typedef SharedHandle<DefaultBtRequestFactory> DefaultBtRequestFactoryHandle; typedef SharedHandle<DefaultBtRequestFactory> DefaultBtRequestFactoryHandle;

View file

@ -57,6 +57,9 @@
namespace aria2 { namespace aria2 {
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory(): DefaultExtensionMessageFactory::DefaultExtensionMessageFactory():
messageFactory_(0),
dispatcher_(0),
tracker_(0),
logger_(LogFactory::getInstance()) {} logger_(LogFactory::getInstance()) {}
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory DefaultExtensionMessageFactory::DefaultExtensionMessageFactory

View file

@ -58,11 +58,11 @@ private:
SharedHandle<DownloadContext> dctx_; SharedHandle<DownloadContext> dctx_;
WeakHandle<BtMessageFactory> messageFactory_; BtMessageFactory* messageFactory_;
WeakHandle<BtMessageDispatcher> dispatcher_; BtMessageDispatcher* dispatcher_;
WeakHandle<UTMetadataRequestTracker> tracker_; UTMetadataRequestTracker* tracker_;
Logger* logger_; Logger* logger_;
@ -93,18 +93,17 @@ public:
dctx_ = dctx; dctx_ = dctx;
} }
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory) void setBtMessageFactory(BtMessageFactory* factory)
{ {
messageFactory_ = factory; messageFactory_ = factory;
} }
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& disp) void setBtMessageDispatcher(BtMessageDispatcher* disp)
{ {
dispatcher_ = disp; dispatcher_ = disp;
} }
void setUTMetadataRequestTracker void setUTMetadataRequestTracker(UTMetadataRequestTracker* tracker)
(const WeakHandle<UTMetadataRequestTracker>& tracker)
{ {
tracker_ = tracker; tracker_ = tracker;
} }

View file

@ -92,7 +92,7 @@ bool DefaultPeerStorage::isPeerAlreadyAdded(const SharedHandle<Peer>& peer)
namespace { namespace {
size_t calculateMaxPeerListSize(const SharedHandle<BtRuntime>& btRuntime) size_t calculateMaxPeerListSize(const SharedHandle<BtRuntime>& btRuntime)
{ {
if(btRuntime.isNull()) { if(!btRuntime) {
return MAX_PEER_LIST_SIZE; return MAX_PEER_LIST_SIZE;
} }
return btRuntime->getMaxPeers() == 0 ? return btRuntime->getMaxPeers() == 0 ?
@ -199,7 +199,7 @@ size_t DefaultPeerStorage::countPeer() const {
} }
bool DefaultPeerStorage::isPeerAvailable() { bool DefaultPeerStorage::isPeerAvailable() {
return !getUnusedPeer().isNull(); return getUnusedPeer();
} }
namespace { namespace {

View file

@ -89,7 +89,7 @@ SharedHandle<Piece> DefaultPieceStorage::checkOutPiece(size_t index)
bitfieldMan_->setUseBit(index); bitfieldMan_->setUseBit(index);
SharedHandle<Piece> piece = findUsedPiece(index); SharedHandle<Piece> piece = findUsedPiece(index);
if(piece.isNull()) { if(!piece) {
piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index))); piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index)));
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
@ -114,7 +114,7 @@ SharedHandle<Piece> DefaultPieceStorage::getPiece(size_t index)
SharedHandle<Piece> piece; SharedHandle<Piece> piece;
if(0 <= index && index <= bitfieldMan_->getMaxIndex()) { if(0 <= index && index <= bitfieldMan_->getMaxIndex()) {
piece = findUsedPiece(index); piece = findUsedPiece(index);
if(piece.isNull()) { if(!piece) {
piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index))); piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index)));
if(hasPiece(index)) { if(hasPiece(index)) {
piece->setAllBlock(); piece->setAllBlock();
@ -147,7 +147,7 @@ SharedHandle<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
if(i != usedPieces_.end() && *(*i) == *p) { if(i != usedPieces_.end() && *(*i) == *p) {
return *i; return *i;
} else { } else {
p.reset(0); p.reset();
return p; return p;
} }
} }
@ -363,7 +363,7 @@ SharedHandle<Piece> DefaultPieceStorage::getMissingPiece(size_t index)
void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece) void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
{ {
if(piece.isNull()) { if(!piece) {
return; return;
} }
std::deque<SharedHandle<Piece> >::iterator i = std::deque<SharedHandle<Piece> >::iterator i =
@ -412,7 +412,7 @@ void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece) void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece)
{ {
if(piece.isNull()) { if(!piece) {
return; return;
} }
deleteUsedPiece(piece); deleteUsedPiece(piece);
@ -456,7 +456,7 @@ bool DefaultPieceStorage::isSelectiveDownloadingMode()
// not unittested // not unittested
void DefaultPieceStorage::cancelPiece(const SharedHandle<Piece>& piece) void DefaultPieceStorage::cancelPiece(const SharedHandle<Piece>& piece)
{ {
if(piece.isNull()) { if(!piece) {
return; return;
} }
bitfieldMan_->unsetUseBit(piece->getIndex()); bitfieldMan_->unsetUseBit(piece->getIndex());

View file

@ -315,11 +315,11 @@ bool DownloadCommand::prepareForNextSegment() {
} }
SharedHandle<Segment> nextSegment = getSegmentMan()->getSegmentWithIndex SharedHandle<Segment> nextSegment = getSegmentMan()->getSegmentWithIndex
(getCuid(), tempSegment->getIndex()+1); (getCuid(), tempSegment->getIndex()+1);
if(nextSegment.isNull()) { if(!nextSegment) {
nextSegment = getSegmentMan()->getCleanSegmentIfOwnerIsIdle nextSegment = getSegmentMan()->getCleanSegmentIfOwnerIsIdle
(getCuid(), tempSegment->getIndex()+1); (getCuid(), tempSegment->getIndex()+1);
} }
if(nextSegment.isNull() || nextSegment->getWrittenLength() > 0) { if(!nextSegment || nextSegment->getWrittenLength() > 0) {
// If nextSegment->getWrittenLength() > 0, current socket must // If nextSegment->getWrittenLength() > 0, current socket must
// be closed because writing incoming data at // be closed because writing incoming data at
// nextSegment->getWrittenLength() corrupts file. // nextSegment->getWrittenLength() corrupts file.
@ -362,7 +362,7 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
void DownloadCommand::installStreamFilter void DownloadCommand::installStreamFilter
(const SharedHandle<StreamFilter>& streamFilter) (const SharedHandle<StreamFilter>& streamFilter)
{ {
if(streamFilter.isNull()) { if(!streamFilter) {
return; return;
} }
streamFilter->installDelegate(streamFilter_); streamFilter->installDelegate(streamFilter_);

View file

@ -205,7 +205,7 @@ bool DownloadEngine::deleteSocketForWriteCheck(const SocketHandle& socket,
void DownloadEngine::calculateStatistics() void DownloadEngine::calculateStatistics()
{ {
if(!statCalc_.isNull()) { if(statCalc_) {
statCalc_->calculateStat(this); statCalc_->calculateStat(this);
} }
} }
@ -360,7 +360,7 @@ void DownloadEngine::poolSocket(const SharedHandle<Request>& request,
const SharedHandle<SocketCore>& socket, const SharedHandle<SocketCore>& socket,
time_t timeout) time_t timeout)
{ {
if(proxyRequest.isNull()) { if(!proxyRequest) {
std::pair<std::string, uint16_t> peerInfo; std::pair<std::string, uint16_t> peerInfo;
socket->getPeerInfo(peerInfo); socket->getPeerInfo(peerInfo);
poolSocket(peerInfo.first, peerInfo.second, poolSocket(peerInfo.first, peerInfo.second,
@ -381,7 +381,7 @@ void DownloadEngine::poolSocket
const std::map<std::string, std::string>& options, const std::map<std::string, std::string>& options,
time_t timeout) time_t timeout)
{ {
if(proxyRequest.isNull()) { if(!proxyRequest) {
std::pair<std::string, uint16_t> peerInfo; std::pair<std::string, uint16_t> peerInfo;
socket->getPeerInfo(peerInfo); socket->getPeerInfo(peerInfo);
poolSocket(peerInfo.first, peerInfo.second, username, poolSocket(peerInfo.first, peerInfo.second, username,
@ -456,7 +456,7 @@ DownloadEngine::popPooledSocket
for(std::vector<std::string>::const_iterator i = ipaddrs.begin(), for(std::vector<std::string>::const_iterator i = ipaddrs.begin(),
eoi = ipaddrs.end(); i != eoi; ++i) { eoi = ipaddrs.end(); i != eoi; ++i) {
s = popPooledSocket(*i, port, A2STR::NIL, 0); s = popPooledSocket(*i, port, A2STR::NIL, 0);
if(!s.isNull()) { if(s) {
break; break;
} }
} }
@ -473,7 +473,7 @@ DownloadEngine::popPooledSocket
for(std::vector<std::string>::const_iterator i = ipaddrs.begin(), for(std::vector<std::string>::const_iterator i = ipaddrs.begin(),
eoi = ipaddrs.end(); i != eoi; ++i) { eoi = ipaddrs.end(); i != eoi; ++i) {
s = popPooledSocket(options, *i, port, username, A2STR::NIL, 0); s = popPooledSocket(options, *i, port, username, A2STR::NIL, 0);
if(!s.isNull()) { if(s) {
break; break;
} }
} }

View file

@ -47,7 +47,7 @@ DownloadHandler::~DownloadHandler() {}
bool DownloadHandler::canHandle(const RequestGroup* requestGroup) const bool DownloadHandler::canHandle(const RequestGroup* requestGroup) const
{ {
return !criteria_.isNull() && criteria_->match(requestGroup); return criteria_ && criteria_->match(requestGroup);
} }
void DownloadHandler::setCriteria(const RequestGroupCriteriaHandle& criteria) void DownloadHandler::setCriteria(const RequestGroupCriteriaHandle& criteria)

View file

@ -69,7 +69,7 @@ DownloadHandlerFactory::btMetadataPostDownloadHandler_;
SharedHandle<MemoryBufferPreDownloadHandler> SharedHandle<MemoryBufferPreDownloadHandler>
DownloadHandlerFactory::getMetalinkPreDownloadHandler() DownloadHandlerFactory::getMetalinkPreDownloadHandler()
{ {
if(metalinkPreDownloadHandler_.isNull()) { if(!metalinkPreDownloadHandler_) {
metalinkPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler()); metalinkPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler());
RequestGroupCriteriaHandle criteria RequestGroupCriteriaHandle criteria
@ -86,7 +86,7 @@ DownloadHandlerFactory::getMetalinkPreDownloadHandler()
SharedHandle<MetalinkPostDownloadHandler> SharedHandle<MetalinkPostDownloadHandler>
DownloadHandlerFactory::getMetalinkPostDownloadHandler() DownloadHandlerFactory::getMetalinkPostDownloadHandler()
{ {
if(metalinkPostDownloadHandler_.isNull()) { if(!metalinkPostDownloadHandler_) {
metalinkPostDownloadHandler_.reset(new MetalinkPostDownloadHandler()); metalinkPostDownloadHandler_.reset(new MetalinkPostDownloadHandler());
} }
return metalinkPostDownloadHandler_; return metalinkPostDownloadHandler_;
@ -99,7 +99,7 @@ DownloadHandlerFactory::getMetalinkPostDownloadHandler()
SharedHandle<MemoryBufferPreDownloadHandler> SharedHandle<MemoryBufferPreDownloadHandler>
DownloadHandlerFactory::getBtPreDownloadHandler() DownloadHandlerFactory::getBtPreDownloadHandler()
{ {
if(btPreDownloadHandler_.isNull()) { if(!btPreDownloadHandler_) {
btPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler()); btPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler());
RequestGroupCriteriaHandle criteria RequestGroupCriteriaHandle criteria
@ -116,7 +116,7 @@ DownloadHandlerFactory::getBtPreDownloadHandler()
SharedHandle<BtPostDownloadHandler> SharedHandle<BtPostDownloadHandler>
DownloadHandlerFactory::getBtPostDownloadHandler() DownloadHandlerFactory::getBtPostDownloadHandler()
{ {
if(btPostDownloadHandler_.isNull()) { if(!btPostDownloadHandler_) {
btPostDownloadHandler_.reset(new BtPostDownloadHandler()); btPostDownloadHandler_.reset(new BtPostDownloadHandler());
} }
return btPostDownloadHandler_; return btPostDownloadHandler_;
@ -125,7 +125,7 @@ DownloadHandlerFactory::getBtPostDownloadHandler()
SharedHandle<UTMetadataPostDownloadHandler> SharedHandle<UTMetadataPostDownloadHandler>
DownloadHandlerFactory::getUTMetadataPostDownloadHandler() DownloadHandlerFactory::getUTMetadataPostDownloadHandler()
{ {
if(btMetadataPostDownloadHandler_.isNull()) { if(!btMetadataPostDownloadHandler_) {
btMetadataPostDownloadHandler_.reset(new UTMetadataPostDownloadHandler()); btMetadataPostDownloadHandler_.reset(new UTMetadataPostDownloadHandler());
} }
return btMetadataPostDownloadHandler_; return btMetadataPostDownloadHandler_;

View file

@ -64,7 +64,7 @@ std::string Exception::stackTrace() const
} }
s << what() << "\n"; s << what() << "\n";
SharedHandle<Exception> e = cause_; SharedHandle<Exception> e = cause_;
while(!e.isNull()) { while(e) {
s << " -> " << "[" << e->file_ << ":" << e->line_ << "] " s << " -> " << "[" << e->file_ << ":" << e->line_ << "] "
<< e->what() << "\n"; << e->what() << "\n";
e = e->cause_; e = e->cause_;

View file

@ -122,7 +122,7 @@ FeatureConfig::FeatureConfig() {
const SharedHandle<FeatureConfig>& FeatureConfig::getInstance() const SharedHandle<FeatureConfig>& FeatureConfig::getInstance()
{ {
if(featureConfig_.isNull()) { if(!featureConfig_) {
featureConfig_.reset(new FeatureConfig()); featureConfig_.reset(new FeatureConfig());
} }
return featureConfig_; return featureConfig_;

View file

@ -115,7 +115,7 @@ std::string FeedbackURISelector::selectRarer
} }
SharedHandle<ServerStat> ss = SharedHandle<ServerStat> ss =
serverStatMan_->find(us.host, us.protocol); serverStatMan_->find(us.host, us.protocol);
if(!ss.isNull() && ss->isError()) { if(ss && ss->isError()) {
if(logger_->debug()) { if(logger_->debug()) {
logger_->debug("Error not considered: %s", (*i).c_str()); logger_->debug("Error not considered: %s", (*i).c_str());
} }
@ -161,7 +161,7 @@ std::string FeedbackURISelector::selectFaster
} }
SharedHandle<ServerStat> ss = SharedHandle<ServerStat> ss =
serverStatMan_->find(us.host, us.protocol); serverStatMan_->find(us.host, us.protocol);
if(ss.isNull()) { if(!ss) {
normCands.push_back(*i); normCands.push_back(*i);
} else if(ss->isOK()) { } else if(ss->isOK()) {
if(ss->getDownloadSpeed() > SPEED_THRESHOLD) { if(ss->getDownloadSpeed() > SPEED_THRESHOLD) {

View file

@ -160,7 +160,7 @@ FileEntry::getRequest
} }
} }
uris_.insert(uris_.begin(), pending.begin(), pending.end()); uris_.insert(uris_.begin(), pending.begin(), pending.end());
if(g == 0 && uriReuse && req.isNull() && uris_.size() == pending.size()) { if(g == 0 && uriReuse && !req && uris_.size() == pending.size()) {
// Reuse URIs other than ones in pending // Reuse URIs other than ones in pending
reuseUri(ignoreHost); reuseUri(ignoreHost);
} else { } else {
@ -187,12 +187,12 @@ FileEntry::findFasterRequest(const SharedHandle<Request>& base)
return SharedHandle<Request>(); return SharedHandle<Request>();
} }
const SharedHandle<PeerStat>& fastest = requestPool_.front()->getPeerStat(); const SharedHandle<PeerStat>& fastest = requestPool_.front()->getPeerStat();
if(fastest.isNull()) { if(!fastest) {
return SharedHandle<Request>(); return SharedHandle<Request>();
} }
const SharedHandle<PeerStat>& basestat = base->getPeerStat(); const SharedHandle<PeerStat>& basestat = base->getPeerStat();
// TODO hard coded value. See PREF_STARTUP_IDLE_TIME // TODO hard coded value. See PREF_STARTUP_IDLE_TIME
if(basestat.isNull() || if(!basestat ||
(basestat->getDownloadStartTime(). (basestat->getDownloadStartTime().
difference(global::wallclock) >= startupIdleTime && difference(global::wallclock) >= startupIdleTime &&
fastest->getAvgDownloadSpeed()*0.8 > basestat->calculateDownloadSpeed())){ fastest->getAvgDownloadSpeed()*0.8 > basestat->calculateDownloadSpeed())){
@ -212,10 +212,10 @@ public:
bool operator()(const SharedHandle<Request>& lhs, bool operator()(const SharedHandle<Request>& lhs,
const SharedHandle<Request>& rhs) const const SharedHandle<Request>& rhs) const
{ {
if(lhs->getPeerStat().isNull()) { if(!lhs->getPeerStat()) {
return false; return false;
} }
if(rhs->getPeerStat().isNull()) { if(!rhs->getPeerStat()) {
return true; return true;
} }
return return
@ -227,7 +227,7 @@ public:
void FileEntry::storePool(const SharedHandle<Request>& request) void FileEntry::storePool(const SharedHandle<Request>& request)
{ {
const SharedHandle<PeerStat>& peerStat = request->getPeerStat(); const SharedHandle<PeerStat>& peerStat = request->getPeerStat();
if(!peerStat.isNull()) { if(peerStat) {
// We need to calculate average download speed here in order to // We need to calculate average download speed here in order to
// store Request in the right position in the pool. // store Request in the right position in the pool.
peerStat->calculateAvgDownloadSpeed(); peerStat->calculateAvgDownloadSpeed();

View file

@ -315,7 +315,7 @@ void writeFilePath
(InputIterator first, InputIterator last, std::ostream& o, bool memory) (InputIterator first, InputIterator last, std::ostream& o, bool memory)
{ {
SharedHandle<FileEntry> e = getFirstRequestedFileEntry(first, last); SharedHandle<FileEntry> e = getFirstRequestedFileEntry(first, last);
if(e.isNull()) { if(!e) {
o << "n/a"; o << "n/a";
} else { } else {
if(e->getPath().empty()) { if(e->getPath().empty()) {

View file

@ -291,7 +291,7 @@ bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
{ {
if(socketBuffer_.sendBufferIsEmpty()) { if(socketBuffer_.sendBufferIsEmpty()) {
std::string request = "REST "; std::string request = "REST ";
if(segment.isNull()) { if(!segment) {
request += "0"; request += "0";
} else { } else {
request += util::itos(segment->getPositionToWrite()); request += util::itos(segment->getPositionToWrite());

View file

@ -77,7 +77,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
const SharedHandle<Request>& proxyRequest) const SharedHandle<Request>& proxyRequest)
{ {
Command* command; Command* command;
if(!proxyRequest.isNull()) { if(proxyRequest) {
std::map<std::string, std::string> options; std::map<std::string, std::string> options;
SharedHandle<SocketCore> pooledSocket; SharedHandle<SocketCore> pooledSocket;
std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol()); std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol());
@ -92,7 +92,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
(getRequest(), getOption().get())->getUser(), (getRequest(), getOption().get())->getUser(),
proxyRequest->getHost(), proxyRequest->getPort()); proxyRequest->getHost(), proxyRequest->getPort());
} }
if(pooledSocket.isNull()) { if(!pooledSocket) {
if(getLogger()->info()) { if(getLogger()->info()) {
getLogger()->info(MSG_CONNECTING_TO_SERVER, getLogger()->info(MSG_CONNECTING_TO_SERVER,
util::itos(getCuid()).c_str(), addr.c_str(), port); util::itos(getCuid()).c_str(), addr.c_str(), port);
@ -157,7 +157,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
getRequest()->getPort(), getRequest()->getPort(),
getDownloadEngine()->getAuthConfigFactory()->createAuthConfig getDownloadEngine()->getAuthConfigFactory()->createAuthConfig
(getRequest(), getOption().get())->getUser()); (getRequest(), getOption().get())->getUser());
if(pooledSocket.isNull()) { if(!pooledSocket) {
if(getLogger()->info()) { if(getLogger()->info()) {
getLogger()->info(MSG_CONNECTING_TO_SERVER, getLogger()->info(MSG_CONNECTING_TO_SERVER,
util::itos(getCuid()).c_str(), addr.c_str(), port); util::itos(getCuid()).c_str(), addr.c_str(), port);

View file

@ -444,7 +444,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
SharedHandle<CheckIntegrityEntry> checkIntegrityEntry = SharedHandle<CheckIntegrityEntry> checkIntegrityEntry =
getRequestGroup()->createCheckIntegrityEntry(); getRequestGroup()->createCheckIntegrityEntry();
if(checkIntegrityEntry.isNull()) { if(!checkIntegrityEntry) {
sequence_ = SEQ_DOWNLOAD_ALREADY_COMPLETED; sequence_ = SEQ_DOWNLOAD_ALREADY_COMPLETED;
poolConnection(); poolConnection();
return false; return false;
@ -475,7 +475,7 @@ bool FtpNegotiationCommand::recvSize() {
(StringFormat(EX_TOO_LARGE_FILE, (StringFormat(EX_TOO_LARGE_FILE,
util::uitos(size, true).c_str()).str()); util::uitos(size, true).c_str()).str());
} }
if(getPieceStorage().isNull()) { if(!getPieceStorage()) {
sequence_ = SEQ_FILE_PREPARATION; sequence_ = SEQ_FILE_PREPARATION;
return onFileSizeDetermined(size); return onFileSizeDetermined(size);
@ -492,7 +492,7 @@ bool FtpNegotiationCommand::recvSize() {
// Even if one of the other servers waiting in the queue supports SIZE // Even if one of the other servers waiting in the queue supports SIZE
// command, resuming and segmented downloading are disabled when the first // command, resuming and segmented downloading are disabled when the first
// contacted FTP server doesn't support it. // contacted FTP server doesn't support it.
if(getPieceStorage().isNull()) { if(!getPieceStorage()) {
getDownloadContext()->markTotalLengthIsUnknown(); getDownloadContext()->markTotalLengthIsUnknown();
return onFileSizeDetermined(0); return onFileSizeDetermined(0);
@ -747,7 +747,7 @@ bool FtpNegotiationCommand::sendTunnelRequest()
bool FtpNegotiationCommand::recvTunnelResponse() bool FtpNegotiationCommand::recvTunnelResponse()
{ {
SharedHandle<HttpResponse> httpResponse = http_->receiveResponse(); SharedHandle<HttpResponse> httpResponse = http_->receiveResponse();
if(httpResponse.isNull()) { if(!httpResponse) {
return false; return false;
} }
if(httpResponse->getResponseStatus() != HttpHeader::S200) { if(httpResponse->getResponseStatus() != HttpHeader::S200) {
@ -788,7 +788,7 @@ bool FtpNegotiationCommand::recvRest(const SharedHandle<Segment>& segment) {
// If we recieve negative response and requested file position is not 0, // If we recieve negative response and requested file position is not 0,
// then throw exception here. // then throw exception here.
if(status != 350) { if(status != 350) {
if(!segment.isNull() && segment->getPositionToWrite() != 0) { if(segment && segment->getPositionToWrite() != 0) {
throw DL_ABORT_EX2("FTP server doesn't support resuming.", throw DL_ABORT_EX2("FTP server doesn't support resuming.",
downloadresultcode::CANNOT_RESUME); downloadresultcode::CANNOT_RESUME);
} }

View file

@ -65,7 +65,7 @@ void HaveEraseCommand::process()
PieceStorageHandle ps = PieceStorageHandle ps =
getDownloadEngine()->getRequestGroupMan()->getRequestGroup(i)-> getDownloadEngine()->getRequestGroupMan()->getRequestGroup(i)->
getPieceStorage(); getPieceStorage();
if(!ps.isNull()) { if(ps) {
ps->removeAdvertisedPiece(5); ps->removeAdvertisedPiece(5);
} }
} }

View file

@ -71,13 +71,13 @@ Command* HttpInitiateConnectionCommand::createNextCommand
const SharedHandle<Request>& proxyRequest) const SharedHandle<Request>& proxyRequest)
{ {
Command* command; Command* command;
if(!proxyRequest.isNull()) { if(proxyRequest) {
SharedHandle<SocketCore> pooledSocket = SharedHandle<SocketCore> pooledSocket =
getDownloadEngine()->popPooledSocket getDownloadEngine()->popPooledSocket
(getRequest()->getHost(), getRequest()->getPort(), (getRequest()->getHost(), getRequest()->getPort(),
proxyRequest->getHost(), proxyRequest->getPort()); proxyRequest->getHost(), proxyRequest->getPort());
std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol()); std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol());
if(pooledSocket.isNull()) { if(!pooledSocket) {
if(getLogger()->info()) { if(getLogger()->info()) {
getLogger()->info(MSG_CONNECTING_TO_SERVER, getLogger()->info(MSG_CONNECTING_TO_SERVER,
util::itos(getCuid()).c_str(), addr.c_str(), port); util::itos(getCuid()).c_str(), addr.c_str(), port);
@ -132,7 +132,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand
SharedHandle<SocketCore> pooledSocket = SharedHandle<SocketCore> pooledSocket =
getDownloadEngine()->popPooledSocket getDownloadEngine()->popPooledSocket
(resolvedAddresses, getRequest()->getPort()); (resolvedAddresses, getRequest()->getPort());
if(pooledSocket.isNull()) { if(!pooledSocket) {
if(getLogger()->info()) { if(getLogger()->info()) {
getLogger()->info(MSG_CONNECTING_TO_SERVER, getLogger()->info(MSG_CONNECTING_TO_SERVER,
util::itos(getCuid()).c_str(), addr.c_str(), port); util::itos(getCuid()).c_str(), addr.c_str(), port);

View file

@ -58,7 +58,7 @@ HttpListenCommand::HttpListenCommand
HttpListenCommand::~HttpListenCommand() HttpListenCommand::~HttpListenCommand()
{ {
if(!serverSocket_.isNull()) { if(serverSocket_) {
e_->deleteSocketForReadCheck(serverSocket_, this); e_->deleteSocketForReadCheck(serverSocket_, this);
} }
} }
@ -95,7 +95,7 @@ bool HttpListenCommand::execute()
bool HttpListenCommand::bindPort(uint16_t port) bool HttpListenCommand::bindPort(uint16_t port)
{ {
if(!serverSocket_.isNull()) { if(serverSocket_) {
e_->deleteSocketForReadCheck(serverSocket_, this); e_->deleteSocketForReadCheck(serverSocket_, this);
} }
serverSocket_.reset(new SocketCore()); serverSocket_.reset(new SocketCore());
@ -123,7 +123,7 @@ bool HttpListenCommand::bindPort(uint16_t port)
family_ == AF_INET?4:6); family_ == AF_INET?4:6);
getLogger()->error(MSG_BIND_FAILURE, e, getLogger()->error(MSG_BIND_FAILURE, e,
util::itos(getCuid()).c_str(), port); util::itos(getCuid()).c_str(), port);
if(!serverSocket_.isNull()) { if(serverSocket_) {
e_->deleteSocketForReadCheck(serverSocket_, this); e_->deleteSocketForReadCheck(serverSocket_, this);
} }
serverSocket_->closeConnection(); serverSocket_->closeConnection();

View file

@ -74,7 +74,7 @@ void HttpRequest::setRequest(const SharedHandle<Request>& request)
off_t HttpRequest::getStartByte() const off_t HttpRequest::getStartByte() const
{ {
if(segment_.isNull()) { if(!segment_) {
return 0; return 0;
} else { } else {
return fileEntry_->gtoloff(segment_->getPositionToWrite()); return fileEntry_->gtoloff(segment_->getPositionToWrite());
@ -83,7 +83,7 @@ off_t HttpRequest::getStartByte() const
off_t HttpRequest::getEndByte() const off_t HttpRequest::getEndByte() const
{ {
if(segment_.isNull() || request_.isNull()) { if(!segment_ || !request_) {
return 0; return 0;
} else { } else {
if(request_->isPipeliningEnabled()) { if(request_->isPipeliningEnabled()) {
@ -99,7 +99,7 @@ off_t HttpRequest::getEndByte() const
RangeHandle HttpRequest::getRange() const RangeHandle HttpRequest::getRange() const
{ {
// content-length is always 0 // content-length is always 0
if(segment_.isNull()) { if(!segment_) {
return SharedHandle<Range>(new Range()); return SharedHandle<Range>(new Range());
} else { } else {
return SharedHandle<Range>(new Range(getStartByte(), getEndByte(), return SharedHandle<Range>(new Range(getStartByte(), getEndByte(),
@ -109,7 +109,7 @@ RangeHandle HttpRequest::getRange() const
bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const
{ {
if(segment_.isNull()) { if(!segment_) {
return true; return true;
} }
if((getStartByte() == range->getStartByte()) && if((getStartByte() == range->getStartByte()) &&
@ -139,9 +139,9 @@ std::string HttpRequest::createRequest()
authConfig_ = authConfigFactory_->createAuthConfig(request_, option_); authConfig_ = authConfigFactory_->createAuthConfig(request_, option_);
std::string requestLine = request_->getMethod(); std::string requestLine = request_->getMethod();
requestLine += " "; requestLine += " ";
if(!proxyRequest_.isNull()) { if(proxyRequest_) {
if(getProtocol() == Request::PROTO_FTP && if(getProtocol() == Request::PROTO_FTP &&
request_->getUsername().empty() && !authConfig_.isNull()) { request_->getUsername().empty() && authConfig_) {
// Insert user into URI, like ftp://USER@host/ // Insert user into URI, like ftp://USER@host/
std::string uri = getCurrentURI(); std::string uri = getCurrentURI();
assert(uri.size() >= 6); assert(uri.size() >= 6);
@ -192,7 +192,7 @@ std::string HttpRequest::createRequest()
if(!request_->isKeepAliveEnabled() && !request_->isPipeliningEnabled()) { if(!request_->isKeepAliveEnabled() && !request_->isPipeliningEnabled()) {
builtinHds.push_back(std::make_pair("Connection:", "close")); builtinHds.push_back(std::make_pair("Connection:", "close"));
} }
if(!segment_.isNull() && segment_->getLength() > 0 && if(segment_ && segment_->getLength() > 0 &&
(request_->isPipeliningEnabled() || getStartByte() > 0)) { (request_->isPipeliningEnabled() || getStartByte() > 0)) {
std::string rangeHeader = "bytes="; std::string rangeHeader = "bytes=";
rangeHeader += util::itos(getStartByte()); rangeHeader += util::itos(getStartByte());
@ -205,17 +205,17 @@ std::string HttpRequest::createRequest()
} }
builtinHds.push_back(std::make_pair("Range:", rangeHeader)); builtinHds.push_back(std::make_pair("Range:", rangeHeader));
} }
if(!proxyRequest_.isNull()) { if(proxyRequest_) {
if(request_->isKeepAliveEnabled() || request_->isPipeliningEnabled()) { if(request_->isKeepAliveEnabled() || request_->isPipeliningEnabled()) {
builtinHds.push_back(std::make_pair("Proxy-Connection:", "Keep-Alive")); builtinHds.push_back(std::make_pair("Proxy-Connection:", "Keep-Alive"));
} else { } else {
builtinHds.push_back(std::make_pair("Proxy-Connection:", "close")); builtinHds.push_back(std::make_pair("Proxy-Connection:", "close"));
} }
} }
if(!proxyRequest_.isNull() && !proxyRequest_->getUsername().empty()) { if(proxyRequest_ && !proxyRequest_->getUsername().empty()) {
builtinHds.push_back(getProxyAuthString()); builtinHds.push_back(getProxyAuthString());
} }
if(!authConfig_.isNull()) { if(authConfig_) {
builtinHds.push_back builtinHds.push_back
(std::make_pair("Authorization:", (std::make_pair("Authorization:",
strconcat("Basic ", strconcat("Basic ",
@ -224,7 +224,7 @@ std::string HttpRequest::createRequest()
if(getPreviousURI().size()) { if(getPreviousURI().size()) {
builtinHds.push_back(std::make_pair("Referer:", getPreviousURI())); builtinHds.push_back(std::make_pair("Referer:", getPreviousURI()));
} }
if(!cookieStorage_.isNull()) { if(cookieStorage_) {
std::string cookiesValue; std::string cookiesValue;
std::vector<Cookie> cookies = std::vector<Cookie> cookies =
cookieStorage_->criteriaFind cookieStorage_->criteriaFind
@ -270,7 +270,7 @@ std::string HttpRequest::createRequest()
std::string HttpRequest::createProxyRequest() const std::string HttpRequest::createProxyRequest() const
{ {
assert(!proxyRequest_.isNull()); assert(proxyRequest_);
std::string hostport = getURIHost(); std::string hostport = getURIHost();
strappend(hostport, ":", util::uitos(getPort())); strappend(hostport, ":", util::uitos(getPort()));
@ -344,12 +344,12 @@ void HttpRequest::setProxyRequest(const SharedHandle<Request>& proxyRequest)
bool HttpRequest::isProxyRequestSet() const bool HttpRequest::isProxyRequestSet() const
{ {
return !proxyRequest_.isNull(); return proxyRequest_;
} }
bool HttpRequest::authenticationUsed() const bool HttpRequest::authenticationUsed() const
{ {
return !authConfig_.isNull(); return authConfig_;
} }
const SharedHandle<AuthConfig>& HttpRequest::getAuthConfig() const const SharedHandle<AuthConfig>& HttpRequest::getAuthConfig() const

View file

@ -106,7 +106,7 @@ public:
uint64_t getEntityLength() const uint64_t getEntityLength() const
{ {
assert(!fileEntry_.isNull()); assert(fileEntry_);
return fileEntry_->getLength(); return fileEntry_->getLength();
} }

View file

@ -183,7 +183,7 @@ bool HttpRequestCommand::executeInternal() {
if(!httpConnection_->isIssued(segment)) { if(!httpConnection_->isIssued(segment)) {
off_t endOffset = 0; off_t endOffset = 0;
if(getRequestGroup()->getTotalLength() > 0 && if(getRequestGroup()->getTotalLength() > 0 &&
!getPieceStorage().isNull()) { getPieceStorage()) {
size_t nextIndex = size_t nextIndex =
getPieceStorage()->getNextUsedIndex(segment->getIndex()); getPieceStorage()->getNextUsedIndex(segment->getIndex());
endOffset = std::min endOffset = std::min

View file

@ -217,7 +217,7 @@ SharedHandle<StreamFilter> HttpResponse::getContentEncodingStreamFilter() const
uint64_t HttpResponse::getContentLength() const uint64_t HttpResponse::getContentLength() const
{ {
if(httpHeader_.isNull()) { if(!httpHeader_) {
return 0; return 0;
} else { } else {
return httpHeader_->getRange()->getContentLength(); return httpHeader_->getRange()->getContentLength();
@ -226,7 +226,7 @@ uint64_t HttpResponse::getContentLength() const
uint64_t HttpResponse::getEntityLength() const uint64_t HttpResponse::getEntityLength() const
{ {
if(httpHeader_.isNull()) { if(!httpHeader_) {
return 0; return 0;
} else { } else {
return httpHeader_->getRange()->getEntityLength(); return httpHeader_->getRange()->getEntityLength();
@ -235,7 +235,7 @@ uint64_t HttpResponse::getEntityLength() const
std::string HttpResponse::getContentType() const std::string HttpResponse::getContentType() const
{ {
if(httpHeader_.isNull()) { if(!httpHeader_) {
return A2STR::NIL; return A2STR::NIL;
} else { } else {
std::pair<std::string, std::string> p; std::pair<std::string, std::string> p;

View file

@ -87,7 +87,7 @@ SharedHandle<StreamFilter> getTransferEncodingStreamFilter
SharedHandle<StreamFilter> filter; SharedHandle<StreamFilter> filter;
if(httpResponse->isTransferEncodingSpecified()) { if(httpResponse->isTransferEncodingSpecified()) {
filter = httpResponse->getTransferEncodingStreamFilter(); filter = httpResponse->getTransferEncodingStreamFilter();
if(filter.isNull()) { if(!filter) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat(EX_TRANSFER_ENCODING_NOT_SUPPORTED, (StringFormat(EX_TRANSFER_ENCODING_NOT_SUPPORTED,
httpResponse->getTransferEncoding().c_str()).str()); httpResponse->getTransferEncoding().c_str()).str());
@ -95,7 +95,7 @@ SharedHandle<StreamFilter> getTransferEncodingStreamFilter
filter->init(); filter->init();
filter->installDelegate(delegate); filter->installDelegate(delegate);
} }
if(filter.isNull()) { if(!filter) {
filter = delegate; filter = delegate;
} }
return filter; return filter;
@ -110,7 +110,7 @@ SharedHandle<StreamFilter> getContentEncodingStreamFilter
SharedHandle<StreamFilter> filter; SharedHandle<StreamFilter> filter;
if(httpResponse->isContentEncodingSpecified()) { if(httpResponse->isContentEncodingSpecified()) {
filter = httpResponse->getContentEncodingStreamFilter(); filter = httpResponse->getContentEncodingStreamFilter();
if(filter.isNull()) { if(!filter) {
LogFactory::getInstance()->info LogFactory::getInstance()->info
("Content-Encoding %s is specified, but the current implementation" ("Content-Encoding %s is specified, but the current implementation"
"doesn't support it. The decoding process is skipped and the" "doesn't support it. The decoding process is skipped and the"
@ -121,7 +121,7 @@ SharedHandle<StreamFilter> getContentEncodingStreamFilter
filter->installDelegate(delegate); filter->installDelegate(delegate);
} }
} }
if(filter.isNull()) { if(!filter) {
filter = delegate; filter = delegate;
} }
return filter; return filter;
@ -146,7 +146,7 @@ bool HttpResponseCommand::executeInternal()
{ {
SharedHandle<HttpRequest> httpRequest =httpConnection_->getFirstHttpRequest(); SharedHandle<HttpRequest> httpRequest =httpConnection_->getFirstHttpRequest();
SharedHandle<HttpResponse> httpResponse = httpConnection_->receiveResponse(); SharedHandle<HttpResponse> httpResponse = httpConnection_->receiveResponse();
if(httpResponse.isNull()) { if(!httpResponse) {
// The server has not responded to our request yet. // The server has not responded to our request yet.
// For socket->wantRead() == true, setReadCheckSocket(socket) is already // For socket->wantRead() == true, setReadCheckSocket(socket) is already
// done in the constructor. // done in the constructor.
@ -204,7 +204,7 @@ bool HttpResponseCommand::executeInternal()
getFileEntry()->removeURIWhoseHostnameIs(us.host); getFileEntry()->removeURIWhoseHostnameIs(us.host);
} }
} }
if(getPieceStorage().isNull()) { if(!getPieceStorage()) {
uint64_t totalLength = httpResponse->getEntityLength(); uint64_t totalLength = httpResponse->getEntityLength();
getFileEntry()->setLength(totalLength); getFileEntry()->setLength(totalLength);
if(getFileEntry()->getPath().empty()) { if(getFileEntry()->getPath().empty()) {
@ -306,7 +306,7 @@ bool HttpResponseCommand::handleDefaultEncoding
SharedHandle<CheckIntegrityEntry> checkEntry = SharedHandle<CheckIntegrityEntry> checkEntry =
getRequestGroup()->createCheckIntegrityEntry(); getRequestGroup()->createCheckIntegrityEntry();
if(checkEntry.isNull()) { if(!checkEntry) {
return true; return true;
} }
File file(getRequestGroup()->getFirstFilePath()); File file(getRequestGroup()->getFirstFilePath());
@ -322,7 +322,7 @@ bool HttpResponseCommand::handleDefaultEncoding
// Therefore, we shutdown the socket here if pipelining is enabled. // Therefore, we shutdown the socket here if pipelining is enabled.
DownloadCommand* command = 0; DownloadCommand* command = 0;
if(getRequest()->getMethod() == Request::METHOD_GET && if(getRequest()->getMethod() == Request::METHOD_GET &&
!segment.isNull() && segment->getPositionToWrite() == 0 && segment && segment->getPositionToWrite() == 0 &&
!getRequest()->isPipeliningEnabled()) { !getRequest()->isPipeliningEnabled()) {
command = createHttpDownloadCommand command = createHttpDownloadCommand
(httpResponse, (httpResponse,
@ -371,7 +371,7 @@ bool HttpResponseCommand::handleOtherEncoding
getContentEncodingStreamFilter(httpResponse)); getContentEncodingStreamFilter(httpResponse));
// If chunked transfer-encoding is specified, we have to read end of // If chunked transfer-encoding is specified, we have to read end of
// chunk markers(0\r\n\r\n, for example). // chunk markers(0\r\n\r\n, for example).
bool chunkedUsed = !streamFilter.isNull() && bool chunkedUsed = streamFilter &&
streamFilter->getName() == ChunkedDecodingStreamFilter::NAME; streamFilter->getName() == ChunkedDecodingStreamFilter::NAME;
// For zero-length file, check existing file comparing its size // For zero-length file, check existing file comparing its size
@ -448,7 +448,7 @@ bool decideFileAllocation
(const SharedHandle<StreamFilter>& filter) (const SharedHandle<StreamFilter>& filter)
{ {
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
for(SharedHandle<StreamFilter> f = filter; !f.isNull(); f = f->getDelegate()){ for(SharedHandle<StreamFilter> f = filter; f; f = f->getDelegate()){
// Since the compressed file's length are returned in the response header // Since the compressed file's length are returned in the response header
// and the decompressed file size is unknown at this point, disable file // and the decompressed file size is unknown at this point, disable file
// allocation here. // allocation here.

View file

@ -82,7 +82,7 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest()
socket_->readData(buf, size); socket_->readData(buf, size);
SharedHandle<HttpHeader> header = headerProcessor_->getHttpRequestHeader(); SharedHandle<HttpHeader> header = headerProcessor_->getHttpRequestHeader();
if(!header.isNull()) { if(header) {
logger_->info("HTTP Server received request\n%s", logger_->info("HTTP Server received request\n%s",
headerProcessor_->getHeaderString().c_str()); headerProcessor_->getHeaderString().c_str());
lastRequestHeader_ = header; lastRequestHeader_ = header;

View file

@ -101,7 +101,7 @@ bool HttpServerCommand::execute()
header = httpServer_->receiveRequest(); header = httpServer_->receiveRequest();
if(header.isNull()) { if(!header) {
e_->addCommand(this); e_->addCommand(this);
return false; return false;
} }

View file

@ -87,7 +87,7 @@ HttpSkipResponseCommand::~HttpSkipResponseCommand() {}
void HttpSkipResponseCommand::installStreamFilter void HttpSkipResponseCommand::installStreamFilter
(const SharedHandle<StreamFilter>& streamFilter) (const SharedHandle<StreamFilter>& streamFilter)
{ {
if(streamFilter.isNull()) { if(!streamFilter) {
return; return;
} }
streamFilter->installDelegate(streamFilter_); streamFilter->installDelegate(streamFilter_);

View file

@ -77,7 +77,7 @@ bool InitiateConnectionCommand::executeInternal() {
std::string hostname; std::string hostname;
uint16_t port; uint16_t port;
SharedHandle<Request> proxyRequest = createProxyRequest(); SharedHandle<Request> proxyRequest = createProxyRequest();
if(proxyRequest.isNull()) { if(!proxyRequest) {
hostname = getRequest()->getHost(); hostname = getRequest()->getHost();
port = getRequest()->getPort(); port = getRequest()->getPort();
} else { } else {

View file

@ -84,17 +84,17 @@ bool LpdReceiveMessageCommand::execute()
} }
for(size_t i = 0; i < 20; ++i) { for(size_t i = 0; i < 20; ++i) {
SharedHandle<LpdMessage> m = receiver_->receiveMessage(); SharedHandle<LpdMessage> m = receiver_->receiveMessage();
if(m.isNull()) { if(!m) {
break; break;
} }
if(m->getPeer().isNull()) { if(!m->getPeer()) {
// bad message // bad message
continue; continue;
} }
SharedHandle<BtRegistry> reg = e_->getBtRegistry(); SharedHandle<BtRegistry> reg = e_->getBtRegistry();
SharedHandle<DownloadContext> dctx = SharedHandle<DownloadContext> dctx =
reg->getDownloadContext(m->getInfoHash()); reg->getDownloadContext(m->getInfoHash());
if(dctx.isNull()) { if(!dctx) {
if(getLogger()->debug()) { if(getLogger()->debug()) {
getLogger()->debug("Download Context is null for infohash=%s.", getLogger()->debug("Download Context is null for infohash=%s.",
util::toHex(m->getInfoHash()).c_str()); util::toHex(m->getInfoHash()).c_str());
@ -113,7 +113,7 @@ bool LpdReceiveMessageCommand::execute()
BtObject btobj = reg->get(group->getGID()); BtObject btobj = reg->get(group->getGID());
assert(!btobj.isNull()); assert(!btobj.isNull());
SharedHandle<PeerStorage> peerStorage = btobj.peerStorage_; SharedHandle<PeerStorage> peerStorage = btobj.peerStorage_;
assert(!peerStorage.isNull()); assert(peerStorage);
SharedHandle<Peer> peer = m->getPeer(); SharedHandle<Peer> peer = m->getPeer();
if(peerStorage->addPeer(peer)) { if(peerStorage->addPeer(peer)) {
if(getLogger()->debug()) { if(getLogger()->debug()) {

View file

@ -492,7 +492,7 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
break; break;
} }
} }
if(downloadContext.isNull()) { if(!downloadContext) {
throw DL_ABORT_EX("Unknown info hash."); throw DL_ABORT_EX("Unknown info hash.");
} }
initCipher(bittorrent::getInfoHash(downloadContext)); initCipher(bittorrent::getInfoHash(downloadContext));

View file

@ -212,7 +212,7 @@ Metalink2RequestGroup::createRequestGroup
torrentRg = result[0]; torrentRg = result[0];
} }
} }
if(!torrentRg.isNull()) { if(torrentRg) {
torrentRg->setNumConcurrentCommand(1); torrentRg->setNumConcurrentCommand(1);
torrentRg->clearPreDownloadHandler(); torrentRg->clearPreDownloadHandler();
torrentRg->clearPostDownloadHandler(); torrentRg->clearPostDownloadHandler();
@ -242,7 +242,7 @@ Metalink2RequestGroup::createRequestGroup
// make segment size equal to piece hash size. // make segment size equal to piece hash size.
size_t pieceLength; size_t pieceLength;
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(entry->chunkChecksum.isNull()) { if(!entry->chunkChecksum) {
pieceLength = option->getAsInt(PREF_SEGMENT_SIZE); pieceLength = option->getAsInt(PREF_SEGMENT_SIZE);
} else { } else {
pieceLength = entry->chunkChecksum->getChecksumLength(); pieceLength = entry->chunkChecksum->getChecksumLength();
@ -261,11 +261,11 @@ Metalink2RequestGroup::createRequestGroup
dctx->getFirstFileEntry()->setUniqueProtocol(true); dctx->getFirstFileEntry()->setUniqueProtocol(true);
} }
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(!entry->checksum.isNull()) { if(entry->checksum) {
dctx->setChecksum(entry->checksum->getMessageDigest()); dctx->setChecksum(entry->checksum->getMessageDigest());
dctx->setChecksumHashAlgo(entry->checksum->getAlgo()); dctx->setChecksumHashAlgo(entry->checksum->getAlgo());
} }
if(!entry->chunkChecksum.isNull()) { if(entry->chunkChecksum) {
dctx->setPieceHashes(entry->chunkChecksum->getChecksums().begin(), dctx->setPieceHashes(entry->chunkChecksum->getChecksums().begin(),
entry->chunkChecksum->getChecksums().end()); entry->chunkChecksum->getChecksums().end());
dctx->setPieceHashAlgo(entry->chunkChecksum->getAlgo()); dctx->setPieceHashAlgo(entry->chunkChecksum->getAlgo());
@ -314,9 +314,9 @@ Metalink2RequestGroup::createRequestGroup
util::removeMetalinkContentTypes(rg); util::removeMetalinkContentTypes(rg);
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
// Inject depenency between rg and torrentRg here if // Inject depenency between rg and torrentRg here if
// torrentRg.isNull() == false // torrentRg is true
if(!torrentRg.isNull()) { if(torrentRg) {
SharedHandle<Dependency> dep(new BtDependency(rg, torrentRg)); SharedHandle<Dependency> dep(new BtDependency(rg.get(), torrentRg));
rg->dependsOn(dep); rg->dependsOn(dep);
torrentRg->belongsTo(rg->getGID()); torrentRg->belongsTo(rg->getGID());
// metadata download may take very long time. If URIs are // metadata download may take very long time. If URIs are

View file

@ -73,10 +73,10 @@ void MetalinkParserController::newEntryTransaction()
void MetalinkParserController::setFileNameOfEntry(const std::string& filename) void MetalinkParserController::setFileNameOfEntry(const std::string& filename)
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
if(tEntry_->file.isNull()) { if(!tEntry_->file) {
tEntry_->file.reset(new FileEntry(util::escapePath(filename), 0, 0)); tEntry_->file.reset(new FileEntry(util::escapePath(filename), 0, 0));
} else { } else {
tEntry_->file->setPath(util::escapePath(filename)); tEntry_->file->setPath(util::escapePath(filename));
@ -85,10 +85,10 @@ void MetalinkParserController::setFileNameOfEntry(const std::string& filename)
void MetalinkParserController::setFileLengthOfEntry(uint64_t length) void MetalinkParserController::setFileLengthOfEntry(uint64_t length)
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
if(tEntry_->file.isNull()) { if(!tEntry_->file) {
return; return;
} }
tEntry_->file->setLength(length); tEntry_->file->setLength(length);
@ -97,7 +97,7 @@ void MetalinkParserController::setFileLengthOfEntry(uint64_t length)
void MetalinkParserController::setVersionOfEntry(const std::string& version) void MetalinkParserController::setVersionOfEntry(const std::string& version)
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tEntry_->version = version; tEntry_->version = version;
@ -105,7 +105,7 @@ void MetalinkParserController::setVersionOfEntry(const std::string& version)
void MetalinkParserController::setLanguageOfEntry(const std::string& language) void MetalinkParserController::setLanguageOfEntry(const std::string& language)
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tEntry_->languages.push_back(language); tEntry_->languages.push_back(language);
@ -113,7 +113,7 @@ void MetalinkParserController::setLanguageOfEntry(const std::string& language)
void MetalinkParserController::setOSOfEntry(const std::string& os) void MetalinkParserController::setOSOfEntry(const std::string& os)
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tEntry_->oses.push_back(os); tEntry_->oses.push_back(os);
@ -121,7 +121,7 @@ void MetalinkParserController::setOSOfEntry(const std::string& os)
void MetalinkParserController::setMaxConnectionsOfEntry(int maxConnections) void MetalinkParserController::setMaxConnectionsOfEntry(int maxConnections)
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tEntry_->maxConnections = maxConnections; tEntry_->maxConnections = maxConnections;
@ -129,7 +129,7 @@ void MetalinkParserController::setMaxConnectionsOfEntry(int maxConnections)
void MetalinkParserController::commitEntryTransaction() void MetalinkParserController::commitEntryTransaction()
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
commitResourceTransaction(); commitResourceTransaction();
@ -155,7 +155,7 @@ void MetalinkParserController::cancelEntryTransaction()
void MetalinkParserController::newResourceTransaction() void MetalinkParserController::newResourceTransaction()
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tResource_.reset(new MetalinkResource()); tResource_.reset(new MetalinkResource());
@ -163,7 +163,7 @@ void MetalinkParserController::newResourceTransaction()
void MetalinkParserController::setURLOfResource(const std::string& url) void MetalinkParserController::setURLOfResource(const std::string& url)
{ {
if(tResource_.isNull()) { if(!tResource_) {
return; return;
} }
tResource_->url = url; tResource_->url = url;
@ -179,7 +179,7 @@ void MetalinkParserController::setURLOfResource(const std::string& url)
void MetalinkParserController::setTypeOfResource(const std::string& type) void MetalinkParserController::setTypeOfResource(const std::string& type)
{ {
if(tResource_.isNull()) { if(!tResource_) {
return; return;
} }
if(type == MetalinkResource::FTP) { if(type == MetalinkResource::FTP) {
@ -199,7 +199,7 @@ void MetalinkParserController::setTypeOfResource(const std::string& type)
void MetalinkParserController::setLocationOfResource(const std::string& location) void MetalinkParserController::setLocationOfResource(const std::string& location)
{ {
if(tResource_.isNull()) { if(!tResource_) {
return; return;
} }
tResource_->location = location; tResource_->location = location;
@ -207,7 +207,7 @@ void MetalinkParserController::setLocationOfResource(const std::string& location
void MetalinkParserController::setPriorityOfResource(int priority) void MetalinkParserController::setPriorityOfResource(int priority)
{ {
if(tResource_.isNull()) { if(!tResource_) {
return; return;
} }
tResource_->priority = priority; tResource_->priority = priority;
@ -215,7 +215,7 @@ void MetalinkParserController::setPriorityOfResource(int priority)
void MetalinkParserController::setMaxConnectionsOfResource(int maxConnections) void MetalinkParserController::setMaxConnectionsOfResource(int maxConnections)
{ {
if(tResource_.isNull()) { if(!tResource_) {
return; return;
} }
tResource_->maxConnections = maxConnections; tResource_->maxConnections = maxConnections;
@ -223,7 +223,7 @@ void MetalinkParserController::setMaxConnectionsOfResource(int maxConnections)
void MetalinkParserController::commitResourceTransaction() void MetalinkParserController::commitResourceTransaction()
{ {
if(tResource_.isNull()) { if(!tResource_) {
return; return;
} }
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
@ -250,7 +250,7 @@ void MetalinkParserController::cancelResourceTransaction()
void MetalinkParserController::newChecksumTransaction() void MetalinkParserController::newChecksumTransaction()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tChecksum_.reset(new Checksum()); tChecksum_.reset(new Checksum());
@ -260,7 +260,7 @@ void MetalinkParserController::newChecksumTransaction()
void MetalinkParserController::setTypeOfChecksum(const std::string& type) void MetalinkParserController::setTypeOfChecksum(const std::string& type)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChecksum_.isNull()) { if(!tChecksum_) {
return; return;
} }
std::string calgo = MessageDigest::getCanonicalHashType(type); std::string calgo = MessageDigest::getCanonicalHashType(type);
@ -275,7 +275,7 @@ void MetalinkParserController::setTypeOfChecksum(const std::string& type)
void MetalinkParserController::setHashOfChecksum(const std::string& md) void MetalinkParserController::setHashOfChecksum(const std::string& md)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChecksum_.isNull()) { if(!tChecksum_) {
return; return;
} }
if(MessageDigest::isValidHash(tChecksum_->getAlgo(), md)) { if(MessageDigest::isValidHash(tChecksum_->getAlgo(), md)) {
@ -289,10 +289,10 @@ void MetalinkParserController::setHashOfChecksum(const std::string& md)
void MetalinkParserController::commitChecksumTransaction() void MetalinkParserController::commitChecksumTransaction()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChecksum_.isNull()) { if(!tChecksum_) {
return; return;
} }
if(tEntry_->checksum.isNull() || if(!tEntry_->checksum ||
MessageDigest::isStronger(tChecksum_->getAlgo(), MessageDigest::isStronger(tChecksum_->getAlgo(),
tEntry_->checksum->getAlgo())) { tEntry_->checksum->getAlgo())) {
tEntry_->checksum = tChecksum_; tEntry_->checksum = tChecksum_;
@ -311,7 +311,7 @@ void MetalinkParserController::cancelChecksumTransaction()
void MetalinkParserController::newChunkChecksumTransactionV4() void MetalinkParserController::newChunkChecksumTransactionV4()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tChunkChecksumV4_.reset(new ChunkChecksum()); tChunkChecksumV4_.reset(new ChunkChecksum());
@ -322,7 +322,7 @@ void MetalinkParserController::newChunkChecksumTransactionV4()
void MetalinkParserController::setTypeOfChunkChecksumV4(const std::string& type) void MetalinkParserController::setTypeOfChunkChecksumV4(const std::string& type)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksumV4_.isNull()) { if(!tChunkChecksumV4_) {
return; return;
} }
std::string calgo = MessageDigest::getCanonicalHashType(type); std::string calgo = MessageDigest::getCanonicalHashType(type);
@ -337,7 +337,7 @@ void MetalinkParserController::setTypeOfChunkChecksumV4(const std::string& type)
void MetalinkParserController::setLengthOfChunkChecksumV4(size_t length) void MetalinkParserController::setLengthOfChunkChecksumV4(size_t length)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksumV4_.isNull()) { if(!tChunkChecksumV4_) {
return; return;
} }
if(length > 0) { if(length > 0) {
@ -351,7 +351,7 @@ void MetalinkParserController::setLengthOfChunkChecksumV4(size_t length)
void MetalinkParserController::addHashOfChunkChecksumV4(const std::string& md) void MetalinkParserController::addHashOfChunkChecksumV4(const std::string& md)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksumV4_.isNull()) { if(!tChunkChecksumV4_) {
return; return;
} }
if(MessageDigest::isValidHash(tChunkChecksumV4_->getAlgo(), md)) { if(MessageDigest::isValidHash(tChunkChecksumV4_->getAlgo(), md)) {
@ -365,10 +365,10 @@ void MetalinkParserController::addHashOfChunkChecksumV4(const std::string& md)
void MetalinkParserController::commitChunkChecksumTransactionV4() void MetalinkParserController::commitChunkChecksumTransactionV4()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksumV4_.isNull()) { if(!tChunkChecksumV4_) {
return; return;
} }
if(tEntry_->chunkChecksum.isNull() || if(!tEntry_->chunkChecksum ||
MessageDigest::isStronger(tChunkChecksumV4_->getAlgo(), MessageDigest::isStronger(tChunkChecksumV4_->getAlgo(),
tEntry_->chunkChecksum->getAlgo())) { tEntry_->chunkChecksum->getAlgo())) {
std::vector<std::string> checksums(tempChunkChecksumsV4_.begin(), std::vector<std::string> checksums(tempChunkChecksumsV4_.begin(),
@ -390,7 +390,7 @@ void MetalinkParserController::cancelChunkChecksumTransactionV4()
void MetalinkParserController::newChunkChecksumTransaction() void MetalinkParserController::newChunkChecksumTransaction()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tChunkChecksum_.reset(new ChunkChecksum()); tChunkChecksum_.reset(new ChunkChecksum());
@ -401,7 +401,7 @@ void MetalinkParserController::newChunkChecksumTransaction()
void MetalinkParserController::setTypeOfChunkChecksum(const std::string& type) void MetalinkParserController::setTypeOfChunkChecksum(const std::string& type)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksum_.isNull()) { if(!tChunkChecksum_) {
return; return;
} }
std::string calgo = MessageDigest::getCanonicalHashType(type); std::string calgo = MessageDigest::getCanonicalHashType(type);
@ -416,7 +416,7 @@ void MetalinkParserController::setTypeOfChunkChecksum(const std::string& type)
void MetalinkParserController::setLengthOfChunkChecksum(size_t length) void MetalinkParserController::setLengthOfChunkChecksum(size_t length)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksum_.isNull()) { if(!tChunkChecksum_) {
return; return;
} }
if(length > 0) { if(length > 0) {
@ -430,7 +430,7 @@ void MetalinkParserController::setLengthOfChunkChecksum(size_t length)
void MetalinkParserController::addHashOfChunkChecksum(size_t order, const std::string& md) void MetalinkParserController::addHashOfChunkChecksum(size_t order, const std::string& md)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksum_.isNull()) { if(!tChunkChecksum_) {
return; return;
} }
if(MessageDigest::isValidHash(tChunkChecksum_->getAlgo(), md)) { if(MessageDigest::isValidHash(tChunkChecksum_->getAlgo(), md)) {
@ -444,7 +444,7 @@ void MetalinkParserController::addHashOfChunkChecksum(size_t order, const std::s
void MetalinkParserController::createNewHashOfChunkChecksum(size_t order) void MetalinkParserController::createNewHashOfChunkChecksum(size_t order)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksum_.isNull()) { if(!tChunkChecksum_) {
return; return;
} }
tempHashPair_.first = order; tempHashPair_.first = order;
@ -454,7 +454,7 @@ void MetalinkParserController::createNewHashOfChunkChecksum(size_t order)
void MetalinkParserController::setMessageDigestOfChunkChecksum(const std::string& md) void MetalinkParserController::setMessageDigestOfChunkChecksum(const std::string& md)
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksum_.isNull()) { if(!tChunkChecksum_) {
return; return;
} }
if(MessageDigest::isValidHash(tChunkChecksum_->getAlgo(), md)) { if(MessageDigest::isValidHash(tChunkChecksum_->getAlgo(), md)) {
@ -468,7 +468,7 @@ void MetalinkParserController::setMessageDigestOfChunkChecksum(const std::string
void MetalinkParserController::addHashOfChunkChecksum() void MetalinkParserController::addHashOfChunkChecksum()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksum_.isNull()) { if(!tChunkChecksum_) {
return; return;
} }
tempChunkChecksums_.push_back(tempHashPair_); tempChunkChecksums_.push_back(tempHashPair_);
@ -478,10 +478,10 @@ void MetalinkParserController::addHashOfChunkChecksum()
void MetalinkParserController::commitChunkChecksumTransaction() void MetalinkParserController::commitChunkChecksumTransaction()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(tChunkChecksum_.isNull()) { if(!tChunkChecksum_) {
return; return;
} }
if(tEntry_->chunkChecksum.isNull() || if(!tEntry_->chunkChecksum ||
MessageDigest::isStronger(tChunkChecksum_->getAlgo(), MessageDigest::isStronger(tChunkChecksum_->getAlgo(),
tEntry_->chunkChecksum->getAlgo())) { tEntry_->chunkChecksum->getAlgo())) {
std::sort(tempChunkChecksums_.begin(), tempChunkChecksums_.end(), std::sort(tempChunkChecksums_.begin(), tempChunkChecksums_.end(),
@ -506,7 +506,7 @@ void MetalinkParserController::cancelChunkChecksumTransaction()
void MetalinkParserController::newSignatureTransaction() void MetalinkParserController::newSignatureTransaction()
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tSignature_.reset(new Signature()); tSignature_.reset(new Signature());
@ -514,7 +514,7 @@ void MetalinkParserController::newSignatureTransaction()
void MetalinkParserController::setTypeOfSignature(const std::string& type) void MetalinkParserController::setTypeOfSignature(const std::string& type)
{ {
if(tSignature_.isNull()) { if(!tSignature_) {
return; return;
} }
tSignature_->setType(type); tSignature_->setType(type);
@ -522,7 +522,7 @@ void MetalinkParserController::setTypeOfSignature(const std::string& type)
void MetalinkParserController::setFileOfSignature(const std::string& file) void MetalinkParserController::setFileOfSignature(const std::string& file)
{ {
if(tSignature_.isNull()) { if(!tSignature_) {
return; return;
} }
tSignature_->setFile(file); tSignature_->setFile(file);
@ -530,7 +530,7 @@ void MetalinkParserController::setFileOfSignature(const std::string& file)
void MetalinkParserController::setBodyOfSignature(const std::string& body) void MetalinkParserController::setBodyOfSignature(const std::string& body)
{ {
if(tSignature_.isNull()) { if(!tSignature_) {
return; return;
} }
tSignature_->setBody(body); tSignature_->setBody(body);
@ -538,7 +538,7 @@ void MetalinkParserController::setBodyOfSignature(const std::string& body)
void MetalinkParserController::commitSignatureTransaction() void MetalinkParserController::commitSignatureTransaction()
{ {
if(tSignature_.isNull()) { if(!tSignature_) {
return; return;
} }
tEntry_->setSignature(tSignature_); tEntry_->setSignature(tSignature_);
@ -552,7 +552,7 @@ void MetalinkParserController::cancelSignatureTransaction()
void MetalinkParserController::newMetaurlTransaction() void MetalinkParserController::newMetaurlTransaction()
{ {
if(tEntry_.isNull()) { if(!tEntry_) {
return; return;
} }
tMetaurl_.reset(new MetalinkMetaurl()); tMetaurl_.reset(new MetalinkMetaurl());
@ -560,7 +560,7 @@ void MetalinkParserController::newMetaurlTransaction()
void MetalinkParserController::setURLOfMetaurl(const std::string& url) void MetalinkParserController::setURLOfMetaurl(const std::string& url)
{ {
if(tMetaurl_.isNull()) { if(!tMetaurl_) {
return; return;
} }
tMetaurl_->url = url; tMetaurl_->url = url;
@ -569,7 +569,7 @@ void MetalinkParserController::setURLOfMetaurl(const std::string& url)
void MetalinkParserController::setMediatypeOfMetaurl void MetalinkParserController::setMediatypeOfMetaurl
(const std::string& mediatype) (const std::string& mediatype)
{ {
if(tMetaurl_.isNull()) { if(!tMetaurl_) {
return; return;
} }
tMetaurl_->mediatype = mediatype; tMetaurl_->mediatype = mediatype;
@ -577,7 +577,7 @@ void MetalinkParserController::setMediatypeOfMetaurl
void MetalinkParserController::setPriorityOfMetaurl(int priority) void MetalinkParserController::setPriorityOfMetaurl(int priority)
{ {
if(tMetaurl_.isNull()) { if(!tMetaurl_) {
return; return;
} }
tMetaurl_->priority = priority; tMetaurl_->priority = priority;
@ -585,7 +585,7 @@ void MetalinkParserController::setPriorityOfMetaurl(int priority)
void MetalinkParserController::setNameOfMetaurl(const std::string& name) void MetalinkParserController::setNameOfMetaurl(const std::string& name)
{ {
if(tMetaurl_.isNull()) { if(!tMetaurl_) {
return; return;
} }
tMetaurl_->name = name; tMetaurl_->name = name;
@ -593,7 +593,7 @@ void MetalinkParserController::setNameOfMetaurl(const std::string& name)
void MetalinkParserController::commitMetaurlTransaction() void MetalinkParserController::commitMetaurlTransaction()
{ {
if(tMetaurl_.isNull()) { if(!tMetaurl_) {
return; return;
} }
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT

View file

@ -80,7 +80,7 @@ void MetalinkPostDownloadHandler::getNextRequestGroups
requestGroup->followedBy(newRgs.begin(), newRgs.end()); requestGroup->followedBy(newRgs.begin(), newRgs.end());
SharedHandle<MetadataInfo> mi = SharedHandle<MetadataInfo> mi =
createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext()); createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext());
if(!mi.isNull()) { if(mi) {
setMetadataInfo(newRgs.begin(), newRgs.end(), mi); setMetadataInfo(newRgs.begin(), newRgs.end(), mi);
} }
groups.insert(groups.end(), newRgs.begin(), newRgs.end()); groups.insert(groups.end(), newRgs.begin(), newRgs.end());

View file

@ -63,7 +63,7 @@ const std::string& DiskWriterEntry::getFilePath() const
void DiskWriterEntry::initAndOpenFile() void DiskWriterEntry::initAndOpenFile()
{ {
if(!diskWriter_.isNull()) { if(diskWriter_) {
diskWriter_->initAndOpenFile(fileEntry_->getLength()); diskWriter_->initAndOpenFile(fileEntry_->getLength());
if(directIO_) { if(directIO_) {
diskWriter_->enableDirectIO(); diskWriter_->enableDirectIO();
@ -74,7 +74,7 @@ void DiskWriterEntry::initAndOpenFile()
void DiskWriterEntry::openFile() void DiskWriterEntry::openFile()
{ {
if(!diskWriter_.isNull()) { if(diskWriter_) {
diskWriter_->openFile(fileEntry_->getLength()); diskWriter_->openFile(fileEntry_->getLength());
if(directIO_) { if(directIO_) {
diskWriter_->enableDirectIO(); diskWriter_->enableDirectIO();
@ -85,7 +85,7 @@ void DiskWriterEntry::openFile()
void DiskWriterEntry::openExistingFile() void DiskWriterEntry::openExistingFile()
{ {
if(!diskWriter_.isNull()) { if(diskWriter_) {
diskWriter_->openExistingFile(fileEntry_->getLength()); diskWriter_->openExistingFile(fileEntry_->getLength());
if(directIO_) { if(directIO_) {
diskWriter_->enableDirectIO(); diskWriter_->enableDirectIO();

View file

@ -55,7 +55,7 @@ MultiFileAllocationIterator::~MultiFileAllocationIterator() {}
void MultiFileAllocationIterator::allocateChunk() void MultiFileAllocationIterator::allocateChunk()
{ {
while(fileAllocationIterator_.isNull() || while(!fileAllocationIterator_ ||
fileAllocationIterator_->finished()) { fileAllocationIterator_->finished()) {
if(entries_.empty()) { if(entries_.empty()) {
break; break;
@ -92,12 +92,12 @@ void MultiFileAllocationIterator::allocateChunk()
bool MultiFileAllocationIterator::finished() bool MultiFileAllocationIterator::finished()
{ {
return entries_.empty() && return entries_.empty() &&
(fileAllocationIterator_.isNull() || fileAllocationIterator_->finished()); (!fileAllocationIterator_ || fileAllocationIterator_->finished());
} }
off_t MultiFileAllocationIterator::getCurrentLength() off_t MultiFileAllocationIterator::getCurrentLength()
{ {
if(fileAllocationIterator_.isNull()) { if(!fileAllocationIterator_) {
return 0; return 0;
} else { } else {
return fileAllocationIterator_->getCurrentLength(); return fileAllocationIterator_->getCurrentLength();
@ -106,7 +106,7 @@ off_t MultiFileAllocationIterator::getCurrentLength()
uint64_t MultiFileAllocationIterator::getTotalLength() uint64_t MultiFileAllocationIterator::getTotalLength()
{ {
if(fileAllocationIterator_.isNull()) { if(!fileAllocationIterator_) {
return 0; return 0;
} else { } else {
return fileAllocationIterator_->getTotalLength(); return fileAllocationIterator_->getTotalLength();

View file

@ -105,7 +105,7 @@ void Netrc::parse(const std::string& path)
storeAuthenticator(authenticator); storeAuthenticator(authenticator);
authenticator.reset(new DefaultAuthenticator()); authenticator.reset(new DefaultAuthenticator());
} else { } else {
if(authenticator.isNull()) { if(!authenticator) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat("Netrc:parse error. %s encounterd where 'machine'" (StringFormat("Netrc:parse error. %s encounterd where 'machine'"
" or 'default' expected.", token.c_str()).str()); " or 'default' expected.", token.c_str()).str());
@ -145,7 +145,7 @@ void Netrc::parse(const std::string& path)
void Netrc::storeAuthenticator(const SharedHandle<Authenticator>& authenticator) void Netrc::storeAuthenticator(const SharedHandle<Authenticator>& authenticator)
{ {
if(!authenticator.isNull()) { if(authenticator) {
authenticators_.push_back(authenticator); authenticators_.push_back(authenticator);
} }
} }

View file

@ -43,7 +43,7 @@ NetrcAuthResolver::NetrcAuthResolver():ignoreDefault_(false) {}
SharedHandle<AuthConfig> SharedHandle<AuthConfig>
NetrcAuthResolver::resolveAuthConfig(const std::string& hostname) NetrcAuthResolver::resolveAuthConfig(const std::string& hostname)
{ {
if(getUserDefinedAuthConfig().isNull()) { if(!getUserDefinedAuthConfig()) {
return findNetrcAuthenticator(hostname); return findNetrcAuthenticator(hostname);
} else { } else {
return getUserDefinedAuthConfig(); return getUserDefinedAuthConfig();
@ -53,11 +53,11 @@ NetrcAuthResolver::resolveAuthConfig(const std::string& hostname)
SharedHandle<AuthConfig> SharedHandle<AuthConfig>
NetrcAuthResolver::findNetrcAuthenticator(const std::string& hostname) const NetrcAuthResolver::findNetrcAuthenticator(const std::string& hostname) const
{ {
if(netrc_.isNull()) { if(!netrc_) {
return getDefaultAuthConfig(); return getDefaultAuthConfig();
} else { } else {
SharedHandle<Authenticator> auth = netrc_->findAuthenticator(hostname); SharedHandle<Authenticator> auth = netrc_->findAuthenticator(hostname);
if(auth.isNull()) { if(!auth) {
return getDefaultAuthConfig(); return getDefaultAuthConfig();
} else { } else {
if(ignoreDefault_ && auth->getMachine().empty()) { if(ignoreDefault_ && auth->getMachine().empty()) {

View file

@ -154,7 +154,7 @@ void OptionParser::parseArg
} else { } else {
op = findByShortName(c); op = findByShortName(c);
} }
if(op.isNull()) { if(!op) {
throw DL_ABORT_EX("Failed to parse command-line options."); throw DL_ABORT_EX("Failed to parse command-line options.");
} }
out << op->getName() << "="; out << op->getName() << "=";
@ -390,7 +390,7 @@ SharedHandle<OptionParser> OptionParser::optionParser_;
const SharedHandle<OptionParser>& OptionParser::getInstance() const SharedHandle<OptionParser>& OptionParser::getInstance()
{ {
if(optionParser_.isNull()) { if(!optionParser_) {
optionParser_.reset(new OptionParser()); optionParser_.reset(new OptionParser());
optionParser_->setOptionHandlers(OptionHandlerFactory::createOptionHandlers()); optionParser_->setOptionHandlers(OptionHandlerFactory::createOptionHandlers());
} }

View file

@ -54,7 +54,7 @@ void PStringBuildVisitor::visit(PStringSegment& segment)
uris_.push_back(uri); uris_.push_back(uri);
} }
if(!segment.getNext().isNull()) { if(segment.getNext()) {
segment.getNext()->accept(*this); segment.getNext()->accept(*this);
} }

View file

@ -58,7 +58,7 @@ const std::string& PStringSegment::getValue() const
bool PStringSegment::hasNext() const bool PStringSegment::hasNext() const
{ {
return !next_.isNull(); return next_;
} }
SharedHandle<PStringDatum> PStringSegment::getNext() const SharedHandle<PStringDatum> PStringSegment::getNext() const

View file

@ -404,7 +404,7 @@ void Peer::setFirstContactTime(const Timer& time)
firstContactTime_ = time; firstContactTime_ = time;
} }
void Peer::setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt) void Peer::setBtMessageDispatcher(BtMessageDispatcher* dpt)
{ {
assert(res_); assert(res_);
res_->setBtMessageDispatcher(dpt); res_->setBtMessageDispatcher(dpt);

View file

@ -322,7 +322,7 @@ public:
disconnectedGracefully_ = f; disconnectedGracefully_ = f;
} }
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt); void setBtMessageDispatcher(BtMessageDispatcher* dpt);
size_t countOutstandingUpload() const; size_t countOutstandingUpload() const;
}; };

Some files were not shown because too many files have changed in this diff Show more