diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-05-13 14:15:23 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-05-13 14:15:23 +0000 |
| commit | 386d19693bc3b06bea14f8fa606f513b6fe1ac9d (patch) | |
| tree | 0137a837f6ce609ac1319b859a5333e0753f7527 | |
| parent | 9d03f0d2f747c7c66a64081a7cabcf4e02c11020 (diff) | |
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.
59 files changed, 308 insertions, 122 deletions
@@ -1,5 +1,14 @@ 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. * po/ca.po * po/de.po diff --git a/src/A2STR.cc b/src/A2STR.cc new file mode 100644 index 00000000..675045ad --- /dev/null +++ b/src/A2STR.cc @@ -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 diff --git a/src/A2STR.h b/src/A2STR.h new file mode 100644 index 00000000..48a83774 --- /dev/null +++ b/src/A2STR.h @@ -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_ diff --git a/src/AnnounceList.cc b/src/AnnounceList.cc index fa984d03..6629133b 100644 --- a/src/AnnounceList.cc +++ b/src/AnnounceList.cc @@ -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; } } diff --git a/src/AnnounceList.h b/src/AnnounceList.h index 081d05bc..178447e4 100644 --- a/src/AnnounceList.h +++ b/src/AnnounceList.h @@ -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 diff --git a/src/AsyncNameResolver.cc b/src/AsyncNameResolver.cc index e4d2a6ae..bf24c593 100644 --- a/src/AsyncNameResolver.cc +++ b/src/AsyncNameResolver.cc @@ -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); diff --git a/src/AuthConfigFactory.cc b/src/AuthConfigFactory.cc index b41821f8..7be0e1ae 100644 --- a/src/AuthConfigFactory.cc +++ b/src/AuthConfigFactory.cc @@ -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 { diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc index ebb5bdfc..011ed25b 100644 --- a/src/ByteArrayDiskWriter.cc +++ b/src/ByteArrayDiskWriter.cc @@ -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, diff --git a/src/ChunkChecksum.h b/src/ChunkChecksum.h index ab10bf8b..afa20ba9 100644 --- a/src/ChunkChecksum.h +++ b/src/ChunkChecksum.h @@ -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; } } diff --git a/src/Cookie.cc b/src/Cookie.cc index 0f7a8834..dcd95a9f 100644 --- a/src/Cookie.cc +++ b/src/Cookie.cc @@ -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; } diff --git a/src/CookieParser.cc b/src/CookieParser.cc index 31678146..eb1204af 100644 --- a/src/CookieParser.cc +++ b/src/CookieParser.cc @@ -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); diff --git a/src/DHTAbstractMessage.h b/src/DHTAbstractMessage.h index cdef0738..16643a57 100644 --- a/src/DHTAbstractMessage.h +++ b/src/DHTAbstractMessage.h @@ -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(); diff --git a/src/DHTAnnouncePeerMessage.h b/src/DHTAnnouncePeerMessage.h index 7d28cfff..55380d53 100644 --- a/src/DHTAnnouncePeerMessage.h +++ b/src/DHTAnnouncePeerMessage.h @@ -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(); diff --git a/src/DHTFindNodeMessage.h b/src/DHTFindNodeMessage.h index 5a1b5686..1fc9d97c 100644 --- a/src/DHTFindNodeMessage.h +++ b/src/DHTFindNodeMessage.h @@ -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(); diff --git a/src/DHTGetPeersMessage.h b/src/DHTGetPeersMessage.h index 968c572a..42b4d6ce 100644 --- a/src/DHTGetPeersMessage.h +++ b/src/DHTGetPeersMessage.h @@ -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(); diff --git a/src/DHTMessage.h b/src/DHTMessage.h index dcafc645..53bde055 100644 --- a/src/DHTMessage.h +++ b/src/DHTMessage.h @@ -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(); diff --git a/src/DHTMessageFactory.h b/src/DHTMessageFactory.h index a24c0490..3c04eda0 100644 --- a/src/DHTMessageFactory.h +++ b/src/DHTMessageFactory.h @@ -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, diff --git a/src/DHTMessageFactoryImpl.h b/src/DHTMessageFactoryImpl.h index 5f0fc248..7014a3b1 100644 --- a/src/DHTMessageFactoryImpl.h +++ b/src/DHTMessageFactoryImpl.h @@ -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, diff --git a/src/DHTPingMessage.h b/src/DHTPingMessage.h index 62738683..f1be9fe3 100644 --- a/src/DHTPingMessage.h +++ b/src/DHTPingMessage.h @@ -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(); diff --git a/src/DHTQueryMessage.h b/src/DHTQueryMessage.h index 2388c515..76505239 100644 --- a/src/DHTQueryMessage.h +++ b/src/DHTQueryMessage.h @@ -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(); diff --git a/src/DHTResponseMessage.h b/src/DHTResponseMessage.h index 5db6c057..2c4fb03a 100644 --- a/src/DHTResponseMessage.h +++ b/src/DHTResponseMessage.h @@ -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, diff --git a/src/DNSCache.h b/src/DNSCache.h index 7c116192..8c09ede0 100644 --- a/src/DNSCache.h +++ b/src/DNSCache.h @@ -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) {} }; diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index ce2a780b..d45f1be0 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -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()) { diff --git a/src/DefaultBtContext.cc b/src/DefaultBtContext.cc index d0bd748e..22e51ed8 100644 --- a/src/DefaultBtContext.cc +++ b/src/DefaultBtContext.cc @@ -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; } } diff --git a/src/DefaultBtContext.h b/src/DefaultBtContext.h index 0d9ab2b7..224fc8b4 100644 --- a/src/DefaultBtContext.h +++ b/src/DefaultBtContext.h @@ -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()); diff --git a/src/ExtendedMessagingAware.h b/src/ExtendedMessagingAware.h index 5177142b..02803eb7 100644 --- a/src/ExtendedMessagingAware.h +++ b/src/ExtendedMessagingAware.h @@ -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) diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc index dd963664..06b37c09 100644 --- a/src/FeatureConfig.cc +++ b/src/FeatureConfig.cc @@ -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), diff --git a/src/File.cc b/src/File.cc index 7d13b035..afe49bbc 100644 --- a/src/File.cc +++ b/src/File.cc @@ -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 "."; } diff --git a/src/HelpItem.h b/src/HelpItem.h index 64fa1b01..99927174 100644 --- a/src/HelpItem.h +++ b/src/HelpItem.h @@ -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) {} diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 7748a791..e0c19341 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -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); diff --git a/src/HttpHeaderProcessor.cc b/src/HttpHeaderProcessor.cc index 4bfb570e..9dec5099 100644 --- a/src/HttpHeaderProcessor.cc +++ b/src/HttpHeaderProcessor.cc @@ -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() diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index e7c939e2..5b92b9b5 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -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()+";"; diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index 5e15c532..2e4707c5 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -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(); } diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index 265cc9eb..5e120a29 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -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"); } diff --git a/src/InitiateConnectionCommandFactory.cc b/src/InitiateConnectionCommandFactory.cc index 86d9ba80..80503780 100644 --- a/src/InitiateConnectionCommandFactory.cc +++ b/src/InitiateConnectionCommandFactory.cc @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index 7be1c2ab..797c3d7a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/Makefile.in b/src/Makefile.in index 67837790..e63cfe76 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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@ diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 7ced01c7..64366001 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -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 diff --git a/src/MetalinkParserController.cc b/src/MetalinkParserController.cc index 85da8760..d6286506 100644 --- a/src/MetalinkParserController.cc +++ b/src/MetalinkParserController.cc @@ -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; diff --git a/src/MetalinkResource.cc b/src/MetalinkResource.cc index d5376cad..bacb4976 100644 --- a/src/MetalinkResource.cc +++ b/src/MetalinkResource.cc @@ -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) {} diff --git a/src/MetalinkResource.h b/src/MetalinkResource.h index b2afdb4e..889a5674 100644 --- a/src/MetalinkResource.h +++ b/src/MetalinkResource.h @@ -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; diff --git a/src/Netrc.cc b/src/Netrc.cc index b593049d..b025ece3 100644 --- a/src/Netrc.cc +++ b/src/Netrc.cc @@ -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; } } diff --git a/src/Netrc.h b/src/Netrc.h index b18f16aa..160e3435 100644 --- a/src/Netrc.h +++ b/src/Netrc.h @@ -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() {} diff --git a/src/NullProgressInfoFile.h b/src/NullProgressInfoFile.h index 0eb09881..1d4819cb 100644 --- a/src/NullProgressInfoFile.h +++ b/src/NullProgressInfoFile.h @@ -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; } diff --git a/src/Option.cc b/src/Option.cc index 362d9db1..a3b11684 100644 --- a/src/Option.cc +++ b/src/Option.cc @@ -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); diff --git a/src/ParameterizedStringParser.cc b/src/ParameterizedStringParser.cc index 48f31cc7..29e923b8 100644 --- a/src/ParameterizedStringParser.cc +++ b/src/ParameterizedStringParser.cc @@ -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; diff --git a/src/PeerSessionResource.cc b/src/PeerSessionResource.cc index a87bbe6b..a5c54fc7 100644 --- a/src/PeerSessionResource.cc +++ b/src/PeerSessionResource.cc @@ -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) diff --git a/src/Request.cc b/src/Request.cc index c34e7855..5e95708a 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -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+" "; diff --git a/src/Request.h b/src/Request.h index 1bd1f0d6..7ab2fec1 100644 --- a/src/Request.h +++ b/src/Request.h @@ -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; diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 0e295b3b..00480dd4 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -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 : diff --git a/src/SingleFileDownloadContext.cc b/src/SingleFileDownloadContext.cc index 2bfa6ae6..ca13cecb 100644 --- a/src/SingleFileDownloadContext.cc +++ b/src/SingleFileDownloadContext.cc @@ -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"); diff --git a/src/SingleFileDownloadContext.h b/src/SingleFileDownloadContext.h index 1964c65c..ec4e87db 100644 --- a/src/SingleFileDownloadContext.h +++ b/src/SingleFileDownloadContext.h @@ -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; } } diff --git a/src/TaggedItem.cc b/src/TaggedItem.cc index 34777f5c..d03ef146 100644 --- a/src/TaggedItem.cc +++ b/src/TaggedItem.cc @@ -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; } } diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index e8673c28..537ca385 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -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); diff --git a/src/UriListParser.cc b/src/UriListParser.cc index 1b79070f..74f46007 100644 --- a/src/UriListParser.cc +++ b/src/UriListParser.cc @@ -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; } diff --git a/src/Util.cc b/src/Util.cc index 46e2a928..acf8349d 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -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; } } diff --git a/src/a2functional.h b/src/a2functional.h index 99a55268..15f4acc2 100644 --- a/src/a2functional.h +++ b/src/a2functional.h @@ -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 { diff --git a/src/main.cc b/src/main.cc index d69f32fe..b5fb9cae 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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); diff --git a/src/option_processing.cc b/src/option_processing.cc index 65a7581a..df203ab2 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -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; |
