2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Replaced "" with static const variable A2STR::NIL.
	Replaced string comparison against "" with std::string::empty().
	Added PROTO_* to Request class and use them as a protocol string
	constant.
	Made "started", "stopped", "completed" static const variable in
	AnnounceList class.
pull/1/head
Tatsuhiro Tsujikawa 2008-05-13 14:15:23 +00:00
parent 9d03f0d2f7
commit 386d19693b
59 changed files with 308 additions and 122 deletions

View File

@ -1,3 +1,12 @@
2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Replaced "" with static const variable A2STR::NIL.
Replaced string comparison against "" with std::string::empty().
Added PROTO_* to Request class and use them as a protocol string
constant.
Made "started", "stopped", "completed" static const variable in
AnnounceList class.
2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Updated translations. Great thanks to translators.

41
src/A2STR.cc Normal file
View File

@ -0,0 +1,41 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "A2STR.h"
namespace aria2 {
const std::string A2STR::NIL("");
} // namespace aria2

51
src/A2STR.h Normal file
View File

@ -0,0 +1,51 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef _D_A2_STR_H_
#define _D_A2_STR_H_
#include <string>
namespace aria2 {
class A2STR {
private:
A2STR();
public:
static const std::string NIL;
};
} // namespace aria2
#endif // _D_A2_STR_H_

View File

@ -35,10 +35,17 @@
#include "AnnounceList.h"
#include "List.h"
#include "Data.h"
#include "A2STR.h"
#include <algorithm>
namespace aria2 {
const std::string AnnounceList::STARTED("started");
const std::string AnnounceList::STOPPED("stopped");
const std::string AnnounceList::COMPLETED("completed");
AnnounceList::AnnounceList(const MetaEntry* announceListEntry):
currentTrackerInitialized(false) {
reconfigure(announceListEntry);
@ -96,7 +103,7 @@ std::string AnnounceList::getAnnounce() const {
if(currentTrackerInitialized) {
return *currentTracker;
} else {
return "";
return A2STR::NIL;
}
}
@ -146,16 +153,16 @@ std::string AnnounceList::getEventString() const {
switch((*currentTier)->event) {
case AnnounceTier::STARTED:
case AnnounceTier::STARTED_AFTER_COMPLETION:
return "started";
return STARTED;
case AnnounceTier::STOPPED:
return "stopped";
return STOPPED;
case AnnounceTier::COMPLETED:
return "completed";
return COMPLETED;
default:
return "";
return A2STR::NIL;
}
} else {
return "";
return A2STR::NIL;
}
}

View File

@ -127,6 +127,12 @@ public:
bool currentTierAcceptsStoppedEvent() const;
bool currentTierAcceptsCompletedEvent() const;
static const std::string STARTED;
static const std::string STOPPED;
static const std::string COMPLETED;
};
} // namespace aria2

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "AsyncNameResolver.h"
#include "Util.h"
#include "A2STR.h"
#include <cstring>
namespace aria2 {
@ -121,7 +122,7 @@ bool AsyncNameResolver::operator==(const AsyncNameResolver& resolver) const
void AsyncNameResolver::reset()
{
_hostname = "";
_hostname = A2STR::NIL;
_resolvedAddresses.clear();
status = STATUS_READY;
ares_destroy(channel);

View File

@ -51,9 +51,10 @@ AuthConfigFactory::~AuthConfigFactory() {}
AuthConfigHandle
AuthConfigFactory::createAuthConfig(const RequestHandle& request) const
{
if(request->getProtocol() == "http" || request->getProtocol() == "https") {
if(request->getProtocol() == Request::PROTO_HTTP ||
request->getProtocol() == Request::PROTO_HTTPS) {
return createHttpAuthResolver()->resolveAuthConfig(request->getHost());
} else if(request->getProtocol() == "ftp") {
} else if(request->getProtocol() == Request::PROTO_FTP) {
if(!request->getUsername().empty()) {
return createAuthConfig(request->getUsername(), request->getPassword());
} else {

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "ByteArrayDiskWriter.h"
#include "Util.h"
#include "A2STR.h"
namespace aria2 {
@ -43,7 +44,7 @@ ByteArrayDiskWriter::~ByteArrayDiskWriter() {}
void ByteArrayDiskWriter::clear()
{
buf.str("");
buf.str(A2STR::NIL);
}
void ByteArrayDiskWriter::initAndOpenFile(const std::string& filename,

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include "A2STR.h"
#include <string>
#include <deque>
@ -82,7 +83,7 @@ public:
if(index < _checksums.size()) {
return _checksums[index];
} else {
return "";
return A2STR::NIL;
}
}

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "Cookie.h"
#include "Util.h"
#include "A2STR.h"
namespace aria2 {
@ -74,7 +75,7 @@ std::string Cookie::toString() const
void Cookie::clear()
{
name = value = path = domain = "";
name = value = path = domain = A2STR::NIL;
expires = 0;
secure = false;
}

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "CookieParser.h"
#include "Util.h"
#include "A2STR.h"
#include <strings.h>
#include <utility>
#include <istream>
@ -60,7 +61,7 @@ void CookieParser::setField(Cookie& cookie, const std::string& name, const std::
Cookie CookieParser::parse(const std::string& cookieStr) const
{
return parse(cookieStr, "", "");
return parse(cookieStr, A2STR::NIL, A2STR::NIL);
}
Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defaultDomain, const std::string& defaultPath) const
@ -84,7 +85,7 @@ Cookies CookieParser::parse(std::istream& s) const
Cookies cookies;
std::string line;
while(getline(s, line)) {
if(Util::trim(line) == "" || Util::startsWith(line, "#")) {
if(Util::trim(line).empty() || Util::startsWith(line, "#")) {
continue;
}
Cookie cookie = parse(line);

View File

@ -36,6 +36,7 @@
#define _D_DHT_ABSTRACT_MESSAGE_H_
#include "DHTMessage.h"
#include "A2STR.h"
namespace aria2 {
@ -57,7 +58,7 @@ protected:
public:
DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual ~DHTAbstractMessage();

View File

@ -37,6 +37,7 @@
#include "DHTQueryMessage.h"
#include "DHTConstants.h"
#include "A2STR.h"
namespace aria2 {
@ -62,7 +63,7 @@ public:
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual ~DHTAnnouncePeerMessage();

View File

@ -49,7 +49,7 @@ public:
DHTFindNodeMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual ~DHTFindNodeMessage();

View File

@ -37,6 +37,7 @@
#include "DHTQueryMessage.h"
#include "DHTConstants.h"
#include "A2STR.h"
namespace aria2 {
@ -56,7 +57,7 @@ public:
DHTGetPeersMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual ~DHTGetPeersMessage();

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include "A2STR.h"
#include <string>
namespace aria2 {
@ -55,7 +56,7 @@ protected:
public:
DHTMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual ~DHTMessage();

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include "A2STR.h"
#include <string>
#include <deque>
@ -62,7 +63,7 @@ public:
virtual SharedHandle<DHTMessage>
createPingMessage(const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID = "") = 0;
const std::string& transactionID = A2STR::NIL) = 0;
virtual SharedHandle<DHTMessage>
createPingReplyMessage(const SharedHandle<DHTNode>& remoteNode,
@ -72,7 +73,7 @@ public:
virtual SharedHandle<DHTMessage>
createFindNodeMessage(const SharedHandle<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID = "") = 0;
const std::string& transactionID = A2STR::NIL) = 0;
virtual SharedHandle<DHTMessage>
createFindNodeReplyMessage(const SharedHandle<DHTNode>& remoteNode,
@ -82,7 +83,7 @@ public:
virtual SharedHandle<DHTMessage>
createGetPeersMessage(const SharedHandle<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID = "") = 0;
const std::string& transactionID = A2STR::NIL) = 0;
virtual SharedHandle<DHTMessage>
createGetPeersReplyMessage(const SharedHandle<DHTNode>& remoteNode,
@ -101,7 +102,7 @@ public:
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
const std::string& transactionID = "") = 0;
const std::string& transactionID = A2STR::NIL) = 0;
virtual SharedHandle<DHTMessage>
createAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& remoteNode,

View File

@ -36,6 +36,7 @@
#define _D_DHT_MESSAGE_FACTORY_IMPL_H_
#include "DHTMessageFactory.h"
#include "A2STR.h"
namespace aria2 {
@ -94,7 +95,7 @@ public:
virtual SharedHandle<DHTMessage>
createPingMessage(const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual SharedHandle<DHTMessage>
createPingReplyMessage(const SharedHandle<DHTNode>& remoteNode,
@ -104,7 +105,7 @@ public:
virtual SharedHandle<DHTMessage>
createFindNodeMessage(const SharedHandle<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
SharedHandle<DHTMessage>
createFindNodeReplyMessage(const SharedHandle<DHTNode>& remoteNode,
@ -120,7 +121,7 @@ public:
virtual SharedHandle<DHTMessage>
createGetPeersMessage(const SharedHandle<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual SharedHandle<DHTMessage>
createGetPeersReplyMessage(const SharedHandle<DHTNode>& remoteNode,
@ -149,7 +150,7 @@ public:
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual SharedHandle<DHTMessage>
createAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& remoteNode,

View File

@ -36,6 +36,7 @@
#define _D_DHT_PING_MESSAGE_H_
#include "DHTQueryMessage.h"
#include "A2STR.h"
namespace aria2 {
@ -43,7 +44,7 @@ class DHTPingMessage:public DHTQueryMessage {
public:
DHTPingMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual ~DHTPingMessage();

View File

@ -36,16 +36,17 @@
#define _D_DHT_QUERY_MESSAGE_H_
#include "DHTAbstractMessage.h"
#include "A2STR.h"
namespace aria2 {
class DHTQueryMessage:public DHTAbstractMessage {
protected:
virtual std::string toStringOptional() const { return ""; }
virtual std::string toStringOptional() const { return A2STR::NIL; }
public:
DHTQueryMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID = "");
const std::string& transactionID = A2STR::NIL);
virtual ~DHTQueryMessage();

View File

@ -36,12 +36,13 @@
#define _D_DHT_RESPONSE_MESSAGE_H_
#include "DHTAbstractMessage.h"
#include "A2STR.h"
namespace aria2 {
class DHTResponseMessage:public DHTAbstractMessage {
protected:
virtual std::string toStringOptional() const { return ""; }
virtual std::string toStringOptional() const { return A2STR::NIL; }
public:
DHTResponseMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,

View File

@ -38,6 +38,7 @@
#include "common.h"
#include "SharedHandle.h"
#include "SingletonHolder.h"
#include "A2STR.h"
#include <string>
#include <map>
@ -79,7 +80,7 @@ class NullDNSCache : public DNSCache {
public:
virtual ~NullDNSCache() {}
virtual std::string find(const std::string& hostname) { return ""; }
virtual std::string find(const std::string& hostname) { return A2STR::NIL; }
virtual void put(const std::string& hostname, const std::string& ipaddr) {}
};

View File

@ -53,6 +53,7 @@
#include "Peer.h"
#include "Option.h"
#include "StringFormat.h"
#include "A2STR.h"
namespace aria2 {
@ -128,7 +129,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION);
}
} else {
return "";
return A2STR::NIL;
}
unsigned int numWant = 50;
if(!btRuntime->lessThanEqMinPeer() || btRuntime->isHalt()) {

View File

@ -50,6 +50,7 @@
#include "message.h"
#include "PeerMessageUtil.h"
#include "StringFormat.h"
#include "A2STR.h"
#include <cstring>
#include <ostream>
#include <functional>
@ -87,14 +88,14 @@ std::string DefaultBtContext::getInfoHashAsString() const {
void DefaultBtContext::clear() {
memset(infoHash, 0, INFO_HASH_LENGTH);
infoHashString = "";
infoHashString = A2STR::NIL;
pieceHashes.clear();
fileEntries.clear();
totalLength = 0;
pieceLength = 0;
fileMode = BtContext::SINGLE;
numPieces = 0;
name = "";
name = A2STR::NIL;
announceTiers.clear();
_private = false;
}
@ -359,7 +360,7 @@ std::string DefaultBtContext::getPieceHash(size_t index) const {
if(index < numPieces) {
return pieceHashes[index];
} else {
return "";
return A2STR::NIL;
}
}

View File

@ -36,6 +36,7 @@
#define _D_DEFAULT_BT_CONTEXT_H_
#include "BtContext.h"
#include "A2STR.h"
#include <iosfwd>
namespace aria2 {
@ -137,7 +138,7 @@ private:
virtual std::string getActualBasePath() const;
virtual const unsigned char* getPeerId() {
if(peerId == "") {
if(peerId.empty()) {
peerId = generatePeerId();
}
return reinterpret_cast<const unsigned char*>(peerId.c_str());

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "BtConstants.h"
#include "A2STR.h"
#include <string>
namespace aria2 {
@ -76,7 +77,7 @@ public:
return p.first;
}
}
return "";
return A2STR::NIL;
}
void removeExtension(const std::string& name)

View File

@ -35,6 +35,7 @@
#include "FeatureConfig.h"
#include "array_fun.h"
#include "Util.h"
#include "Request.h"
#include <numeric>
namespace aria2 {
@ -78,9 +79,9 @@ const std::string FeatureConfig::FEATURE_ASYNC_DNS("Async DNS");
#endif // ENABLE_ASYNC_DNS
FeatureConfig::FeatureConfig() {
_defaultPorts.insert(PortMap::value_type("http", 80));
_defaultPorts.insert(PortMap::value_type("https", 443));
_defaultPorts.insert(PortMap::value_type("ftp", 21));
_defaultPorts.insert(PortMap::value_type(Request::PROTO_HTTP, 80));
_defaultPorts.insert(PortMap::value_type(Request::PROTO_HTTPS, 443));
_defaultPorts.insert(PortMap::value_type(Request::PROTO_FTP, 21));
FeatureMap::value_type featureArray[] = {
FeatureMap::value_type(FEATURE_HTTPS, HTTPS_ENABLED),

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "File.h"
#include "Util.h"
#include "A2STR.h"
#include <cstring>
#include <stdlib.h>
#include <deque>
@ -142,8 +143,8 @@ std::string File::getDirname() const
{
std::string::size_type lastSlashIndex = name.find_last_of("/");
if(lastSlashIndex == std::string::npos) {
if(name == "") {
return "";
if(name.empty()) {
return A2STR::NIL;
} else {
return ".";
}

View File

@ -36,6 +36,7 @@
#define _D_HELP_ITEM_H_
#include "TaggedItem.h"
#include "A2STR.h"
namespace aria2 {
@ -48,7 +49,7 @@ private:
std::string _defaultValue;
public:
HelpItem(const std::string& name, const std::string& usageText, const std::string& defaultValue = ""):
HelpItem(const std::string& name, const std::string& usageText, const std::string& defaultValue = A2STR::NIL):
TaggedItem(name),
_usageText(usageText),
_defaultValue(defaultValue) {}

View File

@ -35,6 +35,7 @@
#include "HttpHeader.h"
#include "Range.h"
#include "Util.h"
#include "A2STR.h"
#include <istream>
namespace aria2 {
@ -51,7 +52,7 @@ bool HttpHeader::defined(const std::string& name) const {
std::string HttpHeader::getFirst(const std::string& name) const {
std::multimap<std::string, std::string>::const_iterator itr = table.find(Util::toLower(name));
if(itr == table.end()) {
return "";
return A2STR::NIL;
} else {
return (*itr).second;
}
@ -73,7 +74,7 @@ unsigned int HttpHeader::getFirstAsUInt(const std::string& name) const {
uint64_t HttpHeader::getFirstAsULLInt(const std::string& name) const {
std::string value = getFirst(name);
if(value == "") {
if(value.empty()) {
return 0;
} else {
return Util::parseULLInt(value);
@ -83,9 +84,9 @@ uint64_t HttpHeader::getFirstAsULLInt(const std::string& name) const {
RangeHandle HttpHeader::getRange() const
{
std::string rangeStr = getFirst("Content-Range");
if(rangeStr == "") {
if(rangeStr.empty()) {
std::string contentLengthStr = getFirst("Content-Length");
if(contentLengthStr == "") {
if(contentLengthStr.empty()) {
return SharedHandle<Range>(new Range());
} else {
uint64_t contentLength = Util::parseULLInt(contentLengthStr);

View File

@ -38,6 +38,7 @@
#include "Util.h"
#include "DlRetryEx.h"
#include "DlAbortEx.h"
#include "A2STR.h"
namespace aria2 {
@ -90,7 +91,7 @@ size_t HttpHeaderProcessor::getPutBackDataLength() const
void HttpHeaderProcessor::clear()
{
strm.str("");
strm.str(A2STR::NIL);
}
SharedHandle<HttpHeader> HttpHeaderProcessor::getHttpResponseHeader()

View File

@ -134,7 +134,7 @@ std::string HttpRequest::getHostText(const std::string& host, uint16_t port) con
std::string HttpRequest::createRequest() const
{
std::string requestLine = "GET ";
if(getProtocol() == "ftp" || proxyEnabled) {
if(getProtocol() == Request::PROTO_FTP || proxyEnabled) {
requestLine += getCurrentURI();
} else {
if(getDir() == "/") {
@ -193,7 +193,7 @@ std::string HttpRequest::createRequest() const
Cookies cookies = request->cookieBox->criteriaFind(getHost(),
getDir(),
time(0),
getProtocol() == "https" ?
getProtocol() == Request::PROTO_HTTPS ?
true : false);
for(Cookies::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
cookiesValue += (*itr).toString()+";";

View File

@ -95,7 +95,7 @@ createHttpRequest(const SharedHandle<Request>& req,
bool HttpRequestCommand::executeInternal() {
socket->setBlockingMode();
if(req->getProtocol() == "https") {
if(req->getProtocol() == Request::PROTO_HTTPS) {
socket->initiateSecureConnection();
}

View File

@ -46,6 +46,7 @@
#include "message.h"
#include "DlAbortEx.h"
#include "StringFormat.h"
#include "A2STR.h"
#include <deque>
namespace aria2 {
@ -168,7 +169,7 @@ uint64_t HttpResponse::getEntityLength() const
std::string HttpResponse::getContentType() const
{
if(httpHeader.isNull()) {
return "";
return A2STR::NIL;
} else {
return httpHeader->getFirst("Content-Type");
}

View File

@ -47,10 +47,10 @@ namespace aria2 {
Command*
InitiateConnectionCommandFactory::createInitiateConnectionCommand(int32_t cuid, const RequestHandle& req, RequestGroup* requestGroup, DownloadEngine* e) {
if(req->getProtocol() == "http"
if(req->getProtocol() == Request::PROTO_HTTP
#ifdef ENABLE_SSL
// for SSL
|| req->getProtocol() == "https"
|| req->getProtocol() == Request::PROTO_HTTPS
#endif // ENABLE_SSL
) {
@ -62,7 +62,7 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand(int32_t cuid,
}
return new HttpInitiateConnectionCommand(cuid, req, requestGroup, e);
} else if(req->getProtocol() == "ftp") {
} else if(req->getProtocol() == Request::PROTO_FTP) {
return new FtpInitiateConnectionCommand(cuid, req, requestGroup, e);
} else {
// these protocols are not supported yet

View File

@ -186,7 +186,8 @@ SRCS = Socket.h\
StringFormat.cc StringFormat.h\
HttpSkipResponseCommand.cc HttpSkipResponseCommand.h\
InitiateConnectionCommand.cc InitiateConnectionCommand.h\
FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h
FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h\
A2STR.cc A2STR.h
if ENABLE_ASYNC_DNS
SRCS += AsyncNameResolver.cc AsyncNameResolver.h

View File

@ -409,7 +409,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
HttpSkipResponseCommand.cc HttpSkipResponseCommand.h \
InitiateConnectionCommand.cc InitiateConnectionCommand.h \
FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h \
AsyncNameResolver.cc AsyncNameResolver.h \
A2STR.cc A2STR.h AsyncNameResolver.cc AsyncNameResolver.h \
IteratableChunkChecksumValidator.cc \
IteratableChunkChecksumValidator.h \
IteratableChecksumValidator.cc IteratableChecksumValidator.h \
@ -789,12 +789,12 @@ am__objects_15 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
TimedHaltCommand.$(OBJEXT) ProtocolDetector.$(OBJEXT) \
StringFormat.$(OBJEXT) HttpSkipResponseCommand.$(OBJEXT) \
InitiateConnectionCommand.$(OBJEXT) \
FtpFinishDownloadCommand.$(OBJEXT) $(am__objects_1) \
$(am__objects_2) $(am__objects_3) $(am__objects_4) \
$(am__objects_5) $(am__objects_6) $(am__objects_7) \
$(am__objects_8) $(am__objects_9) $(am__objects_10) \
$(am__objects_11) $(am__objects_12) $(am__objects_13) \
$(am__objects_14)
FtpFinishDownloadCommand.$(OBJEXT) A2STR.$(OBJEXT) \
$(am__objects_1) $(am__objects_2) $(am__objects_3) \
$(am__objects_4) $(am__objects_5) $(am__objects_6) \
$(am__objects_7) $(am__objects_8) $(am__objects_9) \
$(am__objects_10) $(am__objects_11) $(am__objects_12) \
$(am__objects_13) $(am__objects_14)
am_libaria2c_a_OBJECTS = $(am__objects_15)
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)"
@ -1133,11 +1133,11 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
HttpSkipResponseCommand.cc HttpSkipResponseCommand.h \
InitiateConnectionCommand.cc InitiateConnectionCommand.h \
FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h \
$(am__append_1) $(am__append_2) $(am__append_3) \
$(am__append_4) $(am__append_5) $(am__append_6) \
$(am__append_7) $(am__append_8) $(am__append_9) \
$(am__append_10) $(am__append_11) $(am__append_12) \
$(am__append_13) $(am__append_14)
A2STR.cc A2STR.h $(am__append_1) $(am__append_2) \
$(am__append_3) $(am__append_4) $(am__append_5) \
$(am__append_6) $(am__append_7) $(am__append_8) \
$(am__append_9) $(am__append_10) $(am__append_11) \
$(am__append_12) $(am__append_13) $(am__append_14)
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@ -1225,6 +1225,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/alloca.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/A2STR.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractAuthResolver.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractBtMessage.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractCommand.Po@am__quote@

View File

@ -48,6 +48,7 @@
#include "MetalinkEntry.h"
#include "MetalinkResource.h"
#include "FileEntry.h"
#include "A2STR.h"
#ifdef ENABLE_BITTORRENT
# include "BtDependency.h"
#endif // ENABLE_BITTORRENT
@ -167,7 +168,7 @@ Metalink2RequestGroup::createRequestGroup
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(_option->getAsInt(PREF_SEGMENT_SIZE),
0,
""));
A2STR::NIL));
//dctx->setDir(_option->get(PREF_DIR));
torrentRg->setDownloadContext(dctx);
torrentRg->clearPreDowloadHandler();
@ -205,7 +206,7 @@ Metalink2RequestGroup::createRequestGroup
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(pieceLength,
entry->getLength(),
"",
A2STR::NIL,
entry->file->getPath()));
dctx->setDir(_option->get(PREF_DIR));
#ifdef ENABLE_MESSAGE_DIGEST

View File

@ -38,6 +38,7 @@
#include "MetalinkResource.h"
#include "FileEntry.h"
#include "a2functional.h"
#include "A2STR.h"
#ifdef ENABLE_MESSAGE_DIGEST
# include "Checksum.h"
# include "ChunkChecksum.h"
@ -86,7 +87,7 @@ void MetalinkParserController::setFileLengthOfEntry(uint64_t length)
return;
}
if(_tEntry->file.isNull()) {
_tEntry->file.reset(new FileEntry("", length, 0));
_tEntry->file.reset(new FileEntry(A2STR::NIL, length, 0));
} else {
_tEntry->file->setLength(length);
}
@ -165,13 +166,13 @@ void MetalinkParserController::setTypeOfResource(const std::string& type)
if(_tResource.isNull()) {
return;
}
if(type == "ftp") {
if(type == MetalinkResource::FTP) {
_tResource->type = MetalinkResource::TYPE_FTP;
} else if(type == "http") {
} else if(type == MetalinkResource::HTTP) {
_tResource->type = MetalinkResource::TYPE_HTTP;
} else if(type == "https") {
} else if(type == MetalinkResource::HTTPS) {
_tResource->type = MetalinkResource::TYPE_HTTPS;
} else if(type == "bittorrent") {
} else if(type == MetalinkResource::BITTORRENT) {
_tResource->type = MetalinkResource::TYPE_BITTORRENT;
} else {
_tResource->type = MetalinkResource::TYPE_NOT_SUPPORTED;

View File

@ -40,6 +40,14 @@ std::string MetalinkResource::type2String[] = {
"ftp", "http", "https", "bittorrent", "not_supported"
};
const std::string MetalinkResource::HTTP("http");
const std::string MetalinkResource::HTTPS("https");
const std::string MetalinkResource::FTP("ftp");
const std::string MetalinkResource::BITTORRENT("bittorrent");
MetalinkResource::MetalinkResource():
maxConnections(-1)
{}

View File

@ -51,6 +51,15 @@ public:
};
static std::string type2String[];
static const std::string HTTP;
static const std::string HTTPS;
static const std::string FTP;
static const std::string BITTORRENT;
public:
std::string url;
TYPE type;

View File

@ -56,7 +56,7 @@ void Netrc::skipMacdef(std::ifstream& f) const
std::string line;
getline(f, line);
while(getline(f, line)) {
if(line == "\r" || line == "") {
if(line == "\r" || line.empty()) {
break;
}
}

View File

@ -37,6 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include "A2STR.h"
#include <string>
#include <deque>
#include <iosfwd>
@ -116,7 +117,7 @@ public:
DefaultAuthenticator(const std::string& login,
const std::string& password,
const std::string& account)
:Authenticator("", login, password, account) {}
:Authenticator(A2STR::NIL, login, password, account) {}
virtual ~DefaultAuthenticator() {}

View File

@ -36,6 +36,7 @@
#define _D_NULL_PROGRESS_INFO_FILE_H_
#include "BtProgressInfoFile.h"
#include "A2STR.h"
namespace aria2 {
@ -45,7 +46,7 @@ public:
virtual std::string getFilename()
{
return "";
return A2STR::NIL;
}
virtual bool exists() { return false; }

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "Option.h"
#include "prefs.h"
#include "A2STR.h"
#include <cstdlib>
namespace aria2 {
@ -53,7 +54,7 @@ bool Option::defined(const std::string& name) const {
std::string Option::get(const std::string& name) const {
std::map<std::string, std::string>::const_iterator itr = table.find(name);
if(itr == table.end()) {
return "";
return A2STR::NIL;
} else {
return (*itr).second;
}
@ -61,7 +62,7 @@ std::string Option::get(const std::string& name) const {
int32_t Option::getAsInt(const std::string& name) const {
std::string value = get(name);
if(value == "") {
if(value.empty()) {
return 0;
} else {
return strtol(value.c_str(), NULL, 10);
@ -70,7 +71,7 @@ int32_t Option::getAsInt(const std::string& name) const {
int64_t Option::getAsLLInt(const std::string& name) const {
std::string value = get(name);
if(value == "") {
if(value.empty()) {
return 0;
} else {
return strtoll(value.c_str(), NULL, 10);
@ -88,7 +89,7 @@ bool Option::getAsBool(const std::string& name) const {
double Option::getAsDouble(const std::string& name) const {
std::string value = get(name);
if(value == "") {
if(value.empty()) {
return 0.0;
} else {
return strtod(value.c_str(), 0);

View File

@ -121,7 +121,7 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src,
loopStr.erase(colonIndex);
}
std::pair<std::string, std::string> range = Util::split(loopStr, "-");
if(range.first == "" || range.second == "") {
if(range.first.empty() || range.second.empty()) {
throw FatalException("Loop range missing.");
}
NumberDecoratorHandle nd;

View File

@ -35,6 +35,7 @@
#include "PeerSessionResource.h"
#include "BitfieldManFactory.h"
#include "BitfieldMan.h"
#include "A2STR.h"
#include <algorithm>
namespace aria2 {
@ -267,7 +268,7 @@ std::string PeerSessionResource::getExtensionName(uint8_t id) const
return p.first;
}
}
return "";
return A2STR::NIL;
}
void PeerSessionResource::addExtension(const std::string& name, uint8_t id)

View File

@ -39,6 +39,7 @@
#include "CookieBox.h"
#include "RecoverableException.h"
#include "StringFormat.h"
#include "A2STR.h"
#include <utility>
namespace aria2 {
@ -47,6 +48,12 @@ const std::string Request::METHOD_GET = "GET";
const std::string Request::METHOD_HEAD = "HEAD";
const std::string Request::PROTO_HTTP("http");
const std::string Request::PROTO_HTTPS("https");
const std::string Request::PROTO_FTP("ftp");
Request::Request():
port(0), tryCount(0),
_supportsPersistentConnection(true),
@ -69,7 +76,7 @@ bool Request::resetUrl() {
}
bool Request::redirectUrl(const std::string& url) {
previousUrl = "";
previousUrl = A2STR::NIL;
_supportsPersistentConnection = true;
return parseUrl(url);
}
@ -84,13 +91,13 @@ bool Request::parseUrl(const std::string& url) {
}
currentUrl = tempUrl;
std::string query;
host = "";
host = A2STR::NIL;
port = 0;
dir = "";
file = "";
_query = "";
_username = "";
_password = "";
dir = A2STR::NIL;
file = A2STR::NIL;
_query = A2STR::NIL;
_username = A2STR::NIL;
_password = A2STR::NIL;
// find query part
std::string queryTemp;
std::string::size_type startQueryIndex = tempUrl.find("?");
@ -126,7 +133,7 @@ bool Request::parseUrl(const std::string& url) {
std::pair<std::string, std::string> hostAndPort;
Util::split(hostAndPort, hostPart, ':');
host = hostAndPort.first;
if(hostAndPort.second != "") {
if(hostAndPort.second != A2STR::NIL) {
try {
port = Util::parseInt(hostAndPort.second);
} catch(RecoverableException& e) {
@ -168,7 +175,7 @@ bool Request::isHexNumber(const char c) const
std::string Request::urlencode(const std::string& src) const
{
if(src.empty()) {
return "";
return A2STR::NIL;
}
size_t lastIndex = src.size()-1;
std::string result = src+" ";

View File

@ -174,6 +174,12 @@ public:
static const std::string METHOD_GET;
static const std::string METHOD_HEAD;
static const std::string PROTO_HTTP;
static const std::string PROTO_HTTPS;
static const std::string PROTO_FTP;
};
typedef SharedHandle<Request> RequestHandle;

View File

@ -71,6 +71,7 @@
#include "Request.h"
#include "FileAllocationIterator.h"
#include "StringFormat.h"
#include "A2STR.h"
#ifdef ENABLE_MESSAGE_DIGEST
# include "CheckIntegrityCommand.h"
#endif // ENABLE_MESSAGE_DIGEST
@ -517,7 +518,7 @@ std::string RequestGroup::getFilePath() const
{
assert(!_downloadContext.isNull());
if(_downloadContext.isNull()) {
return "";
return A2STR::NIL;
} else {
return _downloadContext->getActualBasePath();
}
@ -858,7 +859,7 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
SharedHandle<DownloadResult>(new DownloadResult(_gid,
getFilePath(),
getTotalLength(),
uris.empty() ? "":uris.front(),
uris.empty() ? A2STR::NIL:uris.front(),
uris.size(),
downloadFinished()?
DownloadResult::FINISHED :

View File

@ -51,9 +51,9 @@ SingleFileDownloadContext::SingleFileDownloadContext(size_t pieceLength,
void SingleFileDownloadContext::updateFileEntry()
{
if(_ufilename != "") {
if(!_ufilename.empty()) {
_fileEntry->setPath(_ufilename);
} else if(_filename != "") {
} else if(!_filename.empty()) {
_fileEntry->setPath(_filename);
} else {
_fileEntry->setPath("index.html");

View File

@ -36,6 +36,7 @@
#define _D_SINGLE_FILE_DOWNLOAD_CONTEXT_H_
#include "DownloadContext.h"
#include "A2STR.h"
#include <string>
#include <deque>
@ -70,7 +71,7 @@ public:
SingleFileDownloadContext(size_t pieceLength,
uint64_t totalLength,
const std::string& filename,
const std::string& ufilename = "");
const std::string& ufilename = A2STR::NIL);
virtual ~SingleFileDownloadContext() {}
@ -79,7 +80,7 @@ public:
if(index < _pieceHashes.size()) {
return _pieceHashes[index];
} else {
return "";
return A2STR::NIL;
}
}

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "TaggedItem.h"
#include "a2functional.h"
#include "A2STR.h"
#include <algorithm>
namespace aria2 {
@ -48,7 +49,7 @@ std::string TaggedItem::toTagString() const
}
return s;
} else {
return "";
return A2STR::NIL;
}
}

View File

@ -53,6 +53,7 @@
#include "Option.h"
#include "DlAbortEx.h"
#include "Logger.h"
#include "A2STR.h"
#include <sstream>
namespace aria2 {
@ -176,9 +177,9 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
SingleFileDownloadContextHandle dctx
(new SingleFileDownloadContext(e->option->getAsInt(PREF_SEGMENT_SIZE),
0,
"",
A2STR::NIL,
"[tracker.announce]"));
dctx->setDir("");
dctx->setDir(A2STR::NIL);
rg->setDownloadContext(dctx);
SharedHandle<DiskWriterFactory> dwf(new ByteArrayDiskWriterFactory());
rg->setDiskWriterFactory(dwf);

View File

@ -47,7 +47,7 @@ std::deque<std::string> UriListParser::parseNext(std::istream& in)
std::deque<std::string> uris;
std::string line;
while(getline(in, line)) {
if(Util::trim(line) != "") {
if(!Util::trim(line).empty()) {
Util::slice(uris, line, '\t', true);
return uris;
}

View File

@ -43,6 +43,7 @@
#include "FatalException.h"
#include "FileEntry.h"
#include "StringFormat.h"
#include "A2STR.h"
#include <signal.h>
#include <cerrno>
#include <cassert>
@ -64,7 +65,7 @@ std::string Util::trim(const std::string& src, const std::string& trimCharset)
std::string::size_type sp = src.find_first_not_of(trimCharset);
std::string::size_type ep = src.find_last_not_of(trimCharset);
if(sp == std::string::npos || ep == std::string::npos) {
return "";
return A2STR::NIL;
} else {
return src.substr(sp, ep-sp+1);
}
@ -72,12 +73,12 @@ std::string Util::trim(const std::string& src, const std::string& trimCharset)
void Util::split(std::pair<std::string, std::string>& hp, const std::string& src, char delim)
{
hp.first = "";
hp.second = "";
hp.first = A2STR::NIL;
hp.second = A2STR::NIL;
std::string::size_type p = src.find(delim);
if(p == std::string::npos) {
hp.first = src;
hp.second = "";
hp.second = A2STR::NIL;
} else {
hp.first = trim(src.substr(0, p));
hp.second = trim(src.substr(p+1));
@ -87,12 +88,12 @@ void Util::split(std::pair<std::string, std::string>& hp, const std::string& src
std::pair<std::string, std::string> Util::split(const std::string& src, const std::string& delims)
{
std::pair<std::string, std::string> hp;
hp.first = "";
hp.second = "";
hp.first = A2STR::NIL;
hp.second = A2STR::NIL;
std::string::size_type p = src.find_first_of(delims);
if(p == std::string::npos) {
hp.first = src;
hp.second = "";
hp.second = A2STR::NIL;
} else {
hp.first = trim(src.substr(0, p));
hp.second = trim(src.substr(p+1));
@ -145,7 +146,7 @@ bool Util::startsWith(const std::string& target, const std::string& part) {
if(target.size() < part.size()) {
return false;
}
if(part == "") {
if(part.empty()) {
return true;
}
if(target.find(part) == 0) {
@ -159,7 +160,7 @@ bool Util::endsWith(const std::string& target, const std::string& part) {
if(target.size() < part.size()) {
return false;
}
if(part == "") {
if(part.empty()) {
return true;
}
if(target.rfind(part) == target.size()-part.size()) {
@ -170,7 +171,7 @@ bool Util::endsWith(const std::string& target, const std::string& part) {
}
std::string Util::replace(const std::string& target, const std::string& oldstr, const std::string& newstr) {
if(target == "" || oldstr == "" ) {
if(target.empty() || oldstr.empty()) {
return target;
}
std::string result;
@ -515,12 +516,12 @@ std::string Util::getContentDispositionFilename(const std::string& header) {
std::string keyName = "filename=";
std::string::size_type attributesp = header.find(keyName);
if(attributesp == std::string::npos) {
return "";
return A2STR::NIL;
}
std::string::size_type filenamesp = attributesp+strlen(keyName.c_str());
std::string::size_type filenameep;
if(filenamesp == header.size()) {
return "";
return A2STR::NIL;
}
if(header[filenamesp] == '\'' || header[filenamesp] == '"') {
@ -622,7 +623,7 @@ std::string Util::getHomeDir()
if(p) {
return p;
} else {
return "";
return A2STR::NIL;
}
}

View File

@ -37,6 +37,7 @@
#include <functional>
#include "SharedHandle.h"
#include "A2STR.h"
#include <string>
namespace aria2 {
@ -143,7 +144,7 @@ class Concat {
private:
std::string _delim;
public:
Concat(const std::string& delim = ""):_delim(delim) {}
Concat(const std::string& delim = A2STR::NIL):_delim(delim) {}
std::string operator()(const std::string& s1, const std::string& s2) const
{

View File

@ -65,6 +65,7 @@
#include "ConsoleStatCalc.h"
#include "NullStatCalc.h"
#include "StringFormat.h"
#include "A2STR.h"
#ifdef ENABLE_METALINK
# include "MetalinkHelper.h"
# include "Metalink2RequestGroup.h"
@ -112,13 +113,13 @@ std::deque<std::string> unfoldURI(const std::deque<std::string>& args)
}
RequestGroupHandle createRequestGroup(const Option* op, const std::deque<std::string>& uris,
const std::string& ufilename = "")
const std::string& ufilename = A2STR::NIL)
{
RequestGroupHandle rg(new RequestGroup(op, uris));
SingleFileDownloadContextHandle dctx
(new SingleFileDownloadContext(op->getAsInt(PREF_SEGMENT_SIZE),
0,
"",
A2STR::NIL,
ufilename));
dctx->setDir(op->get(PREF_DIR));
rg->setDownloadContext(dctx);

View File

@ -46,6 +46,7 @@
#include "File.h"
#include "StringFormat.h"
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
@ -62,7 +63,7 @@ extern void showUsage(const std::string& category, const Option* option);
static std::string toBoolArg(const char* optarg)
{
std::string arg;
if(!optarg || std::string(optarg) == "") {
if(!optarg || strlen(optarg) == 0) {
arg = V_TRUE;
} else {
arg = optarg;
@ -508,7 +509,7 @@ Option* option_processing(int argc, char* const argv[])
case 'h':
{
std::string category;
if(optarg == 0 || std::string(optarg) == "") {
if(optarg == 0 || strlen(optarg) == 0) {
category = TAG_BASIC;
} else {
category = optarg;