diff options
Diffstat (limited to 'src')
52 files changed, 541 insertions, 254 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 8fc74f81..c83ef87b 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -521,8 +521,9 @@ void AbstractCommand::setWriteCheckSocketIf } } +namespace { // Returns proxy option value for the given protocol. -static const std::string& getProxyOptionFor +const std::string& getProxyOptionFor (const std::string& proxyPref, const SharedHandle<Option>& option) { if(option->defined(proxyPref)) { @@ -531,10 +532,12 @@ static const std::string& getProxyOptionFor return option->get(PREF_ALL_PROXY); } } +} // namespace +namespace { // Returns proxy URI for given protocol. If no proxy URI is defined, // then returns an empty string. -static const std::string& getProxyUri +const std::string& getProxyUri (const std::string& protocol, const SharedHandle<Option>& option) { if(protocol == Request::PROTO_HTTP) { @@ -547,16 +550,19 @@ static const std::string& getProxyUri return A2STR::NIL; } } +} // namespace +namespace { // Returns true if proxy is defined for the given protocol. Otherwise // returns false. -static bool isProxyRequest +bool isProxyRequest (const std::string& protocol, const SharedHandle<Option>& option) { const std::string& proxyUri = getProxyUri(protocol, option); uri::UriStruct us; return !proxyUri.empty() && uri::parse(us, proxyUri); } +} // namespace namespace { class DomainMatch { @@ -576,8 +582,9 @@ public: }; } // namespace -static bool inNoProxy(const SharedHandle<Request>& req, - const std::string& noProxy) +namespace { +bool inNoProxy(const SharedHandle<Request>& req, + const std::string& noProxy) { std::vector<std::string> entries; util::split(noProxy, std::back_inserter(entries), ",", true); @@ -616,6 +623,7 @@ static bool inNoProxy(const SharedHandle<Request>& req, } return false; } +} // namespace bool AbstractCommand::isProxyDefined() const { diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc index 3c30ebcc..227a0f56 100644 --- a/src/AdaptiveURISelector.cc +++ b/src/AdaptiveURISelector.cc @@ -241,11 +241,13 @@ void AdaptiveURISelector::adjustLowestSpeedLimit } } -static unsigned int getUriMaxSpeed(SharedHandle<ServerStat> ss) +namespace { +unsigned int getUriMaxSpeed(SharedHandle<ServerStat> ss) { return std::max(ss->getSingleConnectionAvgSpeed(), ss->getMultiConnectionAvgSpeed()); } +} // namespace unsigned int AdaptiveURISelector::getMaxDownloadSpeed (const std::deque<std::string>& uris) const diff --git a/src/Base64.cc b/src/Base64.cc index 4b7b6afd..b6f556ea 100644 --- a/src/Base64.cc +++ b/src/Base64.cc @@ -36,7 +36,8 @@ namespace aria2 { -static const char CHAR_TABLE[] = { +namespace { +const char CHAR_TABLE[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', @@ -46,8 +47,10 @@ static const char CHAR_TABLE[] = { 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', }; +} // namespace -static const int INDEX_TABLE[] = { +namespace { +const int INDEX_TABLE[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, @@ -65,6 +68,7 @@ static const int INDEX_TABLE[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; +} // namespace void Base64::encode(unsigned char*& result, size_t& rlength, const unsigned char* src, size_t slength) diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc index 9e7771e4..d5e1e1c1 100644 --- a/src/BitfieldMan.cc +++ b/src/BitfieldMan.cc @@ -198,8 +198,9 @@ bool BitfieldMan::getFirstMissingIndex(size_t& index) const } } +namespace { template<typename Array> -static size_t getStartIndex(size_t index, const Array& bitfield, size_t blocks) { +size_t getStartIndex(size_t index, const Array& bitfield, size_t blocks) { while(index < blocks && bitfield::test(bitfield, blocks, index)) { ++index; } @@ -209,17 +210,21 @@ static size_t getStartIndex(size_t index, const Array& bitfield, size_t blocks) return index; } } +} // namespace +namespace { template<typename Array> -static size_t getEndIndex(size_t index, const Array& bitfield, size_t blocks) { +size_t getEndIndex(size_t index, const Array& bitfield, size_t blocks) { while(index < blocks && !bitfield::test(bitfield, blocks, index)) { ++index; } return index; } +} // namespace +namespace { template<typename Array> -static bool getSparseMissingUnusedIndex +bool getSparseMissingUnusedIndex (size_t& index, size_t minSplitSize, const Array& bitfield, @@ -278,6 +283,7 @@ static bool getSparseMissingUnusedIndex return false; } } +} // namespace bool BitfieldMan::getSparseMissingUnusedIndex (size_t& index, @@ -299,8 +305,9 @@ bool BitfieldMan::getSparseMissingUnusedIndex } } +namespace { template<typename Array> -static bool copyBitfield(unsigned char* dst, const Array& src, size_t blocks) +bool copyBitfield(unsigned char* dst, const Array& src, size_t blocks) { unsigned char bits = 0; size_t len = (blocks+7)/8; @@ -312,6 +319,7 @@ static bool copyBitfield(unsigned char* dst, const Array& src, size_t blocks) bits |= dst[len-1]; return bits != 0; } +} // namespace bool BitfieldMan::getAllMissingIndexes(unsigned char* misbitfield, size_t len) const @@ -438,7 +446,8 @@ bool BitfieldMan::isFilteredAllBitSet() const { } } -static bool testAllBitSet +namespace { +bool testAllBitSet (const unsigned char* bitfield, size_t length, size_t blocks) { if(length == 0) { @@ -451,6 +460,7 @@ static bool testAllBitSet } return bitfield[length-1] == bitfield::lastByteMask(blocks); } +} // namespace bool BitfieldMan::isAllBitSet() const { diff --git a/src/BtDependency.cc b/src/BtDependency.cc index fb8a1c9a..100517a2 100644 --- a/src/BtDependency.cc +++ b/src/BtDependency.cc @@ -59,8 +59,9 @@ BtDependency::BtDependency(const WeakHandle<RequestGroup>& dependant, BtDependency::~BtDependency() {} -static void copyValues(const SharedHandle<FileEntry>& d, - const SharedHandle<FileEntry>& s) +namespace { +void copyValues(const SharedHandle<FileEntry>& d, + const SharedHandle<FileEntry>& s) { d->setRequested(true); d->setPath(s->getPath()); @@ -69,6 +70,7 @@ static void copyValues(const SharedHandle<FileEntry>& d, d->setMaxConnectionPerServer(s->getMaxConnectionPerServer()); d->setUniqueProtocol(s->isUniqueProtocol()); } +} // namespace bool BtDependency::resolve() { diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index a7d2aee9..c1477c52 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -74,7 +74,8 @@ namespace aria2 { -static void printProgress +namespace { +void printProgress (std::ostream& o, const SharedHandle<RequestGroup>& rg, const DownloadEngine* e, const SizeFormatter& sizeFormatter) { @@ -146,6 +147,7 @@ static void printProgress } o << "]"; } +} // namespace namespace { class PrintSummary @@ -176,7 +178,8 @@ public: }; } // namespace -static void printProgressSummary +namespace { +void printProgressSummary (const std::deque<SharedHandle<RequestGroup> >& groups, size_t cols, const DownloadEngine* e, const SizeFormatter& sizeFormatter) @@ -203,6 +206,7 @@ static void printProgressSummary std::for_each(groups.begin(), groups.end(), PrintSummary(cols, e, sizeFormatter)); } +} // namespace ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval, bool humanReadable): summaryInterval_(summaryInterval) diff --git a/src/ContentTypeRequestGroupCriteria.cc b/src/ContentTypeRequestGroupCriteria.cc index d276cd26..078ef7df 100644 --- a/src/ContentTypeRequestGroupCriteria.cc +++ b/src/ContentTypeRequestGroupCriteria.cc @@ -43,8 +43,9 @@ namespace aria2 { +namespace { template<typename InputIterator> -static bool tailMatch +bool tailMatch (InputIterator first, InputIterator last, const std::string& target) { for(; first != last; ++first) { @@ -54,6 +55,7 @@ static bool tailMatch } return false; } +} // namespace bool ContentTypeRequestGroupCriteria::match (const RequestGroup* requestGroup) const diff --git a/src/CookieStorage.cc b/src/CookieStorage.cc index 4582edb4..40cf5544 100644 --- a/src/CookieStorage.cc +++ b/src/CookieStorage.cc @@ -113,10 +113,12 @@ CookieStorage::CookieStorage():logger_(LogFactory::getInstance()) {} CookieStorage::~CookieStorage() {} +namespace { // See CookieStorageTest::testDomainIsFull() in CookieStorageTest.cc -static const size_t DOMAIN_EVICTION_TRIGGER = 2000; +const size_t DOMAIN_EVICTION_TRIGGER = 2000; -static const double DOMAIN_EVICTION_RATE = 0.1; +const double DOMAIN_EVICTION_RATE = 0.1; +} // namespace bool CookieStorage::store(const Cookie& cookie, time_t now) { diff --git a/src/DHTMessageFactoryImpl.cc b/src/DHTMessageFactoryImpl.cc index 61ce023b..9910abe8 100644 --- a/src/DHTMessageFactoryImpl.cc +++ b/src/DHTMessageFactoryImpl.cc @@ -83,7 +83,8 @@ DHTMessageFactoryImpl::getRemoteNode return node; } -static const Dict* getDictionary(const Dict* dict, const std::string& key) +namespace { +const Dict* getDictionary(const Dict* dict, const std::string& key) { const Dict* d = asDict(dict->get(key)); if(d) { @@ -93,8 +94,10 @@ static const Dict* getDictionary(const Dict* dict, const std::string& key) (StringFormat("Malformed DHT message. Missing %s", key.c_str()).str()); } } +} // namespace -static const String* getString(const Dict* dict, const std::string& key) +namespace { +const String* getString(const Dict* dict, const std::string& key) { const String* c = asString(dict->get(key)); if(c) { @@ -104,8 +107,10 @@ static const String* getString(const Dict* dict, const std::string& key) (StringFormat("Malformed DHT message. Missing %s", key.c_str()).str()); } } +} // namespace -static const Integer* getInteger(const Dict* dict, const std::string& key) +namespace { +const Integer* getInteger(const Dict* dict, const std::string& key) { const Integer* c = asInteger(dict->get(key)); if(c) { @@ -115,8 +120,10 @@ static const Integer* getInteger(const Dict* dict, const std::string& key) (StringFormat("Malformed DHT message. Missing %s", key.c_str()).str()); } } +} // namespace -static const String* getString(const List* list, size_t index) +namespace { +const String* getString(const List* list, size_t index) { const String* c = asString(list->get(index)); if(c) { @@ -127,8 +134,10 @@ static const String* getString(const List* list, size_t index) static_cast<unsigned long>(index)).str()); } } +} // namespace -static const Integer* getInteger(const List* list, size_t index) +namespace { +const Integer* getInteger(const List* list, size_t index) { const Integer* c = asInteger(list->get(index)); if(c) { @@ -139,8 +148,10 @@ static const Integer* getInteger(const List* list, size_t index) static_cast<unsigned long>(index)).str()); } } +} // namespace -static const List* getList(const Dict* dict, const std::string& key) +namespace { +const List* getList(const Dict* dict, const std::string& key) { const List* l = asList(dict->get(key)); if(l) { @@ -150,6 +161,7 @@ static const List* getList(const Dict* dict, const std::string& key) (StringFormat("Malformed DHT message. Missing %s", key.c_str()).str()); } } +} // namespace void DHTMessageFactoryImpl::validateID(const String* id) const { @@ -171,7 +183,8 @@ void DHTMessageFactoryImpl::validatePort(const Integer* port) const } } -static void setVersion(const SharedHandle<DHTMessage>& msg, const Dict* dict) +namespace { +void setVersion(const SharedHandle<DHTMessage>& msg, const Dict* dict) { const String* v = asString(dict->get(DHTMessage::V)); if(v) { @@ -180,6 +193,7 @@ static void setVersion(const SharedHandle<DHTMessage>& msg, const Dict* dict) msg->setVersion(A2STR::NIL); } } +} // namespace SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage (const Dict* dict, const std::string& ipaddr, uint16_t port) @@ -274,7 +288,8 @@ DHTMessageFactoryImpl::createResponseMessage return msg; } -static const std::string& getDefaultVersion() +namespace { +const std::string& getDefaultVersion() { static std::string version; if(version.empty()) { @@ -286,6 +301,7 @@ static const std::string& getDefaultVersion() } return version; } +} // namespace void DHTMessageFactoryImpl::setCommonProperty (const SharedHandle<DHTAbstractMessage>& m) diff --git a/src/DHTRoutingTableDeserializer.cc b/src/DHTRoutingTableDeserializer.cc index b3f372e6..ee73736a 100644 --- a/src/DHTRoutingTableDeserializer.cc +++ b/src/DHTRoutingTableDeserializer.cc @@ -57,12 +57,14 @@ DHTRoutingTableDeserializer::DHTRoutingTableDeserializer(int family): DHTRoutingTableDeserializer::~DHTRoutingTableDeserializer() {} -static void readBytes(unsigned char* buf, size_t buflen, - std::istream& in, size_t readlen) +namespace { +void readBytes(unsigned char* buf, size_t buflen, + std::istream& in, size_t readlen) { assert(readlen <= buflen); in.read(reinterpret_cast<char*>(buf), readlen); } +} // namespace #define CHECK_STREAM(in, length) \ if(in.gcount() != length) { \ diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index bcd122c1..faa24aa0 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -103,7 +103,8 @@ bool DefaultBtAnnounce::isAnnounceReady() { isDefaultAnnounceReady(); } -static bool uriHasQuery(const std::string& uri) +namespace { +bool uriHasQuery(const std::string& uri) { uri::UriStruct us; if(uri::parse(us, uri)) { @@ -112,6 +113,7 @@ static bool uriHasQuery(const std::string& uri) return false; } } +} // namespace std::string DefaultBtAnnounce::getAnnounceUrl() { if(isStoppedAnnounceReady()) { diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc index 496f630f..4fae8fbc 100644 --- a/src/DefaultBtProgressInfoFile.cc +++ b/src/DefaultBtProgressInfoFile.cc @@ -66,13 +66,15 @@ namespace aria2 { const std::string DefaultBtProgressInfoFile::V0000("0000"); const std::string DefaultBtProgressInfoFile::V0001("0001"); -static std::string createFilename +namespace { +std::string createFilename (const SharedHandle<DownloadContext>& dctx, const std::string& suffix) { std::string t = dctx->getBasePath(); t += suffix; return t; } +} // namespace DefaultBtProgressInfoFile::DefaultBtProgressInfoFile (const SharedHandle<DownloadContext>& dctx, diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc index eed13b55..a565a82a 100644 --- a/src/DefaultPeerStorage.cc +++ b/src/DefaultPeerStorage.cc @@ -48,7 +48,9 @@ namespace aria2 { -static const int MAX_PEER_LIST_SIZE = 1024; +namespace { +const int MAX_PEER_LIST_SIZE = 1024; +} // namespace DefaultPeerStorage::DefaultPeerStorage(): logger_(LogFactory::getInstance()), @@ -86,7 +88,8 @@ bool DefaultPeerStorage::isPeerAlreadyAdded(const SharedHandle<Peer>& peer) FindIdenticalPeer(peer)) != peers_.end(); } -static size_t calculateMaxPeerListSize(const SharedHandle<BtRuntime>& btRuntime) +namespace { +size_t calculateMaxPeerListSize(const SharedHandle<BtRuntime>& btRuntime) { if(btRuntime.isNull()) { return MAX_PEER_LIST_SIZE; @@ -95,6 +98,7 @@ static size_t calculateMaxPeerListSize(const SharedHandle<BtRuntime>& btRuntime) MAX_PEER_LIST_SIZE : btRuntime->getMaxPeers()+(btRuntime->getMaxPeers() >> 2); } +} // namespace bool DefaultPeerStorage::addPeer(const SharedHandle<Peer>& peer) { if(isPeerAlreadyAdded(peer)) { @@ -220,7 +224,8 @@ void DefaultPeerStorage::getActivePeers std::for_each(peers_.begin(), peers_.end(), CollectActivePeer(activePeers)); } -static TransferStat calculateStatFor(const SharedHandle<Peer>& peer) +namespace { +TransferStat calculateStatFor(const SharedHandle<Peer>& peer) { TransferStat s; s.downloadSpeed = peer->calculateDownloadSpeed(); @@ -229,6 +234,7 @@ static TransferStat calculateStatFor(const SharedHandle<Peer>& peer) s.sessionUploadLength = peer->getSessionUploadLength(); return s; } +} // namespace TransferStat DefaultPeerStorage::calculateStat() { diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 666398ff..5b9d2eaf 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -205,12 +205,14 @@ void DefaultPieceStorage::getMissingPiece } } -static void unsetExcludedIndexes(BitfieldMan& bitfield, - const std::vector<size_t>& excludedIndexes) +namespace { +void unsetExcludedIndexes(BitfieldMan& bitfield, + const std::vector<size_t>& excludedIndexes) { std::for_each(excludedIndexes.begin(), excludedIndexes.end(), std::bind1st(std::mem_fun(&BitfieldMan::unsetBit), &bitfield)); } +} // namespace void DefaultPieceStorage::createFastIndexBitfield (BitfieldMan& bitfield, const SharedHandle<Peer>& peer) diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index a16c0431..ba5620e9 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -70,7 +70,9 @@ namespace aria2 { -static const size_t BUFSIZE = 16*1024; +namespace { +const size_t BUFSIZE = 16*1024; +} // namespace DownloadCommand::DownloadCommand(cuid_t cuid, const SharedHandle<Request>& req, diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 9ce9b440..4b2df23a 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -115,8 +115,9 @@ void DownloadEngine::cleanQueue() { commands_.clear(); } -static void executeCommand(std::deque<Command*>& commands, - Command::STATUS statusFilter) +namespace { +void executeCommand(std::deque<Command*>& commands, + Command::STATUS statusFilter) { size_t max = commands.size(); for(size_t i = 0; i < max; ++i) { @@ -136,6 +137,7 @@ static void executeCommand(std::deque<Command*>& commands, } } } +} // namespace void DownloadEngine::run() { @@ -303,7 +305,8 @@ void DownloadEngine::poolSocket(const std::string& key, } } -static std::string createSockPoolKey +namespace { +std::string createSockPoolKey (const std::string& host, uint16_t port, const std::string& username, const std::string& proxyhost, uint16_t proxyport) @@ -324,6 +327,7 @@ static std::string createSockPoolKey } return key; } +} // namespace void DownloadEngine::poolSocket (const std::string& ipaddr, diff --git a/src/EpollEventPoll.cc b/src/EpollEventPoll.cc index 8d6a542f..abd2960e 100644 --- a/src/EpollEventPoll.cc +++ b/src/EpollEventPoll.cc @@ -138,7 +138,8 @@ void EpollEventPoll::poll(const struct timeval& tv) // DHTEntryPoint...Command) } -static int translateEvents(EventPoll::EventType events) +namespace { +int translateEvents(EventPoll::EventType events) { int newEvents = 0; if(EventPoll::EVENT_READ&events) { @@ -155,6 +156,7 @@ static int translateEvents(EventPoll::EventType events) } return newEvents; } +} // namespace bool EpollEventPoll::addEvents(sock_t socket, const EpollEventPoll::KEvent& event) diff --git a/src/ExpatMetalinkProcessor.cc b/src/ExpatMetalinkProcessor.cc index 51c1bfe9..366256e3 100644 --- a/src/ExpatMetalinkProcessor.cc +++ b/src/ExpatMetalinkProcessor.cc @@ -60,7 +60,8 @@ public: }; } // namespace -static void splitNsName +namespace { +void splitNsName (std::string& localname, std::string& prefix, std::string& nsUri, const std::string& nsName) { @@ -73,8 +74,10 @@ static void splitNsName localname = nsNamePair.second; } } +} // namespace -static void mlStartElement(void* userData, const char* nsName, const char** attrs) +namespace { +void mlStartElement(void* userData, const char* nsName, const char** attrs) { SessionData* sd = reinterpret_cast<SessionData*>(userData); @@ -110,8 +113,10 @@ static void mlStartElement(void* userData, const char* nsName, const char** attr sd->charactersStack_.push_front(A2STR::NIL); } } +} // namespace -static void mlEndElement(void* userData, const char* nsName) +namespace { +void mlEndElement(void* userData, const char* nsName) { std::string localname; std::string prefix; @@ -126,16 +131,20 @@ static void mlEndElement(void* userData, const char* nsName) } sd->stm_->endElement(localname, prefix, nsUri, characters); } +} // namespace -static void mlCharacters(void* userData, const char* ch, int len) +namespace { +void mlCharacters(void* userData, const char* ch, int len) { SessionData* sd = reinterpret_cast<SessionData*>(userData); if(sd->stm_->needsCharactersBuffering()) { sd->charactersStack_.front() += std::string(&ch[0], &ch[len]); } } +} // namespace -static XML_Parser createParser(const SharedHandle<SessionData>& sessionData) +namespace { +XML_Parser createParser(const SharedHandle<SessionData>& sessionData) { XML_Parser parser = XML_ParserCreateNS(0, static_cast<const XML_Char>('\t')); XML_SetUserData(parser, sessionData.get()); @@ -143,8 +152,10 @@ static XML_Parser createParser(const SharedHandle<SessionData>& sessionData) XML_SetCharacterDataHandler(parser, &mlCharacters); return parser; } +} // namespace -static void checkError(XML_Parser parser) +namespace { +void checkError(XML_Parser parser) { if(XML_Parse(parser, 0, 0, 1) == XML_STATUS_ERROR) { throw DL_ABORT_EX(MSG_CANNOT_PARSE_METALINK); @@ -159,6 +170,7 @@ static void checkError(XML_Parser parser) throw DL_ABORT_EX(stm->getErrorString()); } } +} // namespace SharedHandle<Metalinker> MetalinkProcessor::parseFile(const std::string& filename) diff --git a/src/ExpatXmlRpcRequestProcessor.cc b/src/ExpatXmlRpcRequestProcessor.cc index ad24aadc..b353abac 100644 --- a/src/ExpatXmlRpcRequestProcessor.cc +++ b/src/ExpatXmlRpcRequestProcessor.cc @@ -57,7 +57,8 @@ struct SessionData { }; } // namespace -static void mlStartElement(void* userData, const char* name, const char** attrs) +namespace { +void mlStartElement(void* userData, const char* name, const char** attrs) { SessionData* sd = reinterpret_cast<SessionData*>(userData); @@ -78,8 +79,10 @@ static void mlStartElement(void* userData, const char* name, const char** attrs) sd->charactersStack_.push(std::string()); } } +} // namespace -static void mlEndElement(void* userData, const char* name) +namespace { +void mlEndElement(void* userData, const char* name) { SessionData* sd = reinterpret_cast<SessionData*>(userData); std::string characters; @@ -89,14 +92,17 @@ static void mlEndElement(void* userData, const char* name) } sd->stm_->endElement(name, characters); } +} // namespace -static void mlCharacters(void* userData, const char* ch, int len) +namespace { +void mlCharacters(void* userData, const char* ch, int len) { SessionData* sd = reinterpret_cast<SessionData*>(userData); if(sd->stm_->needsCharactersBuffering()) { sd->charactersStack_.top() += std::string(&ch[0], &ch[len]); } } +} // namespace XmlRpcRequest XmlRpcRequestProcessor::parseMemory(const std::string& xml) diff --git a/src/FileEntry.cc b/src/FileEntry.cc index d98dcd91..bd26a1be 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -104,9 +104,9 @@ void FileEntry::getUris(std::vector<std::string>& uris) const uris.insert(uris.end(), uris_.begin(), uris_.end()); } +namespace { template<typename InputIterator, typename OutputIterator> -static OutputIterator -enumerateInFlightHosts +OutputIterator enumerateInFlightHosts (InputIterator first, InputIterator last, OutputIterator out) { for(; first != last; ++first) { @@ -117,6 +117,7 @@ enumerateInFlightHosts } return out; } +} // namespace SharedHandle<Request> FileEntry::getRequest @@ -371,8 +372,9 @@ void FileEntry::releaseRuntimeResource() inFlightRequests_.clear(); } +namespace { template<typename InputIterator, typename T> -static InputIterator findRequestByUri +InputIterator findRequestByUri (InputIterator first, InputIterator last, const T& uri) { for(; first != last; ++first) { @@ -382,6 +384,7 @@ static InputIterator findRequestByUri } return last; } +} // namespace bool FileEntry::removeUri(const std::string& uri) { diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 557b2163..ea49d93a 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -123,7 +123,8 @@ bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const } } -static std::string getHostText(const std::string& host, uint16_t port) +namespace { +std::string getHostText(const std::string& host, uint16_t port) { std::string hosttext = host; if(!(port == 80 || port == 443)) { @@ -131,6 +132,7 @@ static std::string getHostText(const std::string& host, uint16_t port) } return hosttext; } +} // namespace std::string HttpRequest::createRequest() { diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index bc446505..6bea5f84 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -81,7 +81,8 @@ HttpRequestCommand::HttpRequestCommand HttpRequestCommand::~HttpRequestCommand() {} -static SharedHandle<HttpRequest> +namespace { +SharedHandle<HttpRequest> createHttpRequest(const SharedHandle<Request>& req, const SharedHandle<FileEntry>& fileEntry, const SharedHandle<Segment>& segment, @@ -117,6 +118,7 @@ createHttpRequest(const SharedHandle<Request>& req, httpRequest->setEndOffsetOverride(endOffset); return httpRequest; } +} // namespace bool HttpRequestCommand::executeInternal() { //socket->setBlockingMode(); diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index a0fa41a9..2971a0dc 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -79,13 +79,54 @@ namespace aria2 { -static SharedHandle<StreamFilter> getTransferEncodingStreamFilter +namespace { +SharedHandle<StreamFilter> getTransferEncodingStreamFilter (const SharedHandle<HttpResponse>& httpResponse, - const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>()); + const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>()) +{ + SharedHandle<StreamFilter> filter; + if(httpResponse->isTransferEncodingSpecified()) { + filter = httpResponse->getTransferEncodingStreamFilter(); + if(filter.isNull()) { + throw DL_ABORT_EX + (StringFormat(EX_TRANSFER_ENCODING_NOT_SUPPORTED, + httpResponse->getTransferEncoding().c_str()).str()); + } + filter->init(); + filter->installDelegate(delegate); + } + if(filter.isNull()) { + filter = delegate; + } + return filter; +} +} // namespace -static SharedHandle<StreamFilter> getContentEncodingStreamFilter +namespace { +SharedHandle<StreamFilter> getContentEncodingStreamFilter (const SharedHandle<HttpResponse>& httpResponse, - const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>()); + const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>()) +{ + SharedHandle<StreamFilter> filter; + if(httpResponse->isContentEncodingSpecified()) { + filter = httpResponse->getContentEncodingStreamFilter(); + if(filter.isNull()) { + LogFactory::getInstance()->info + ("Content-Encoding %s is specified, but the current implementation" + "doesn't support it. The decoding process is skipped and the" + "downloaded content will be still encoded.", + httpResponse->getContentEncoding().c_str()); + } else { + filter->init(); + filter->installDelegate(delegate); + } + } + if(filter.isNull()) { + filter = delegate; + } + return filter; +} +} // namespace HttpResponseCommand::HttpResponseCommand (cuid_t cuid, @@ -305,51 +346,6 @@ bool HttpResponseCommand::handleDefaultEncoding return true; } -static SharedHandle<StreamFilter> getTransferEncodingStreamFilter -(const SharedHandle<HttpResponse>& httpResponse, - const SharedHandle<StreamFilter>& delegate) -{ - SharedHandle<StreamFilter> filter; - if(httpResponse->isTransferEncodingSpecified()) { - filter = httpResponse->getTransferEncodingStreamFilter(); - if(filter.isNull()) { - throw DL_ABORT_EX - (StringFormat(EX_TRANSFER_ENCODING_NOT_SUPPORTED, - httpResponse->getTransferEncoding().c_str()).str()); - } - filter->init(); - filter->installDelegate(delegate); - } - if(filter.isNull()) { - filter = delegate; - } - return filter; -} - -static SharedHandle<StreamFilter> getContentEncodingStreamFilter -(const SharedHandle<HttpResponse>& httpResponse, - const SharedHandle<StreamFilter>& delegate) -{ - SharedHandle<StreamFilter> filter; - if(httpResponse->isContentEncodingSpecified()) { - filter = httpResponse->getContentEncodingStreamFilter(); - if(filter.isNull()) { - LogFactory::getInstance()->info - ("Content-Encoding %s is specified, but the current implementation" - "doesn't support it. The decoding process is skipped and the" - "downloaded content will be still encoded.", - httpResponse->getContentEncoding().c_str()); - } else { - filter->init(); - filter->installDelegate(delegate); - } - } - if(filter.isNull()) { - filter = delegate; - } - return filter; -} - bool HttpResponseCommand::handleOtherEncoding (const SharedHandle<HttpResponse>& httpResponse) { // We assume that RequestGroup::getTotalLength() == 0 here @@ -448,7 +444,8 @@ bool HttpResponseCommand::skipResponseBody return true; } -static bool decideFileAllocation +namespace { +bool decideFileAllocation (const SharedHandle<StreamFilter>& filter) { #ifdef HAVE_LIBZ @@ -463,6 +460,7 @@ static bool decideFileAllocation #endif // HAVE_LIBZ return true; } +} // namespace HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand (const SharedHandle<HttpResponse>& httpResponse, diff --git a/src/KqueueEventPoll.cc b/src/KqueueEventPoll.cc index 0ddc69f6..6b211b5a 100644 --- a/src/KqueueEventPoll.cc +++ b/src/KqueueEventPoll.cc @@ -148,7 +148,8 @@ void KqueueEventPoll::poll(const struct timeval& tv) // DHTEntryPoint...Command) } -static int translateEvents(EventPoll::EventType events) +namespace { +int translateEvents(EventPoll::EventType events) { int newEvents = 0; if(EventPoll::EVENT_READ&events) { @@ -159,6 +160,7 @@ static int translateEvents(EventPoll::EventType events) } return newEvents; } +} // namespace bool KqueueEventPoll::addEvents (sock_t socket, const KqueueEventPoll::KEvent& event) diff --git a/src/LongestSequencePieceSelector.cc b/src/LongestSequencePieceSelector.cc index bcbb9b8b..28aef585 100644 --- a/src/LongestSequencePieceSelector.cc +++ b/src/LongestSequencePieceSelector.cc @@ -37,7 +37,8 @@ namespace aria2 { -static size_t getStartIndex +namespace { +size_t getStartIndex (size_t from, const unsigned char* bitfield, size_t nbits) { while(from < nbits && !bitfield::test(bitfield, nbits, from)) { @@ -49,8 +50,10 @@ static size_t getStartIndex return from; } } +} // namespace -static size_t getEndIndex +namespace { +size_t getEndIndex (size_t from, const unsigned char* bitfield, size_t nbits) { while(from < nbits && bitfield::test(bitfield, nbits, from)) { @@ -58,6 +61,7 @@ static size_t getEndIndex } return from; } +} // namespace bool LongestSequencePieceSelector::select (size_t& index, const unsigned char* bitfield, size_t nbits) const diff --git a/src/MetalinkParserStateV3Impl.cc b/src/MetalinkParserStateV3Impl.cc index bc65e7e8..36e3d906 100644 --- a/src/MetalinkParserStateV3Impl.cc +++ b/src/MetalinkParserStateV3Impl.cc @@ -81,12 +81,14 @@ public: }; } // namespace +namespace { template<typename Container> -static typename Container::const_iterator findAttr +typename Container::const_iterator findAttr (const Container& attrs, const std::string& localname) { return std::find_if(attrs.begin(), attrs.end(), FindAttr(localname)); } +} // namespace void MetalinkMetalinkParserState::beginElement (MetalinkParserStateMachine* stm, diff --git a/src/MetalinkParserStateV4Impl.cc b/src/MetalinkParserStateV4Impl.cc index 7d95bb76..989a981b 100644 --- a/src/MetalinkParserStateV4Impl.cc +++ b/src/MetalinkParserStateV4Impl.cc @@ -80,12 +80,14 @@ public: }; } // namespace +namespace { template<typename Container> -static typename Container::const_iterator findAttr +typename Container::const_iterator findAttr (const Container& attrs, const std::string& localname) { return std::find_if(attrs.begin(), attrs.end(), FindAttr(localname)); } +} // namespace void MetalinkMetalinkParserStateV4::beginElement (MetalinkParserStateMachine* stm, diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index ff14d5ab..288d06e6 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -144,7 +144,8 @@ MultiDiskAdaptor::MultiDiskAdaptor(): directIOAllowed_(false), readOnly_(false) {} -static SharedHandle<DiskWriterEntry> createDiskWriterEntry +namespace { +SharedHandle<DiskWriterEntry> createDiskWriterEntry (const SharedHandle<FileEntry>& fileEntry, bool needsFileAllocation) { @@ -152,6 +153,7 @@ static SharedHandle<DiskWriterEntry> createDiskWriterEntry entry->needsFileAllocation(needsFileAllocation); return entry; } +} // namespace void MultiDiskAdaptor::resetDiskWriterEntries() { @@ -334,15 +336,18 @@ void MultiDiskAdaptor::closeFile() mem_fun_sh(&DiskWriterEntry::closeFile)); } -static bool isInRange(const DiskWriterEntryHandle entry, off_t offset) +namespace { +bool isInRange(const DiskWriterEntryHandle entry, off_t offset) { return entry->getFileEntry()->getOffset() <= offset && (uint64_t)offset < entry->getFileEntry()->getOffset()+entry->getFileEntry()->getLength(); } +} // namespace -static size_t calculateLength(const DiskWriterEntryHandle entry, - off_t fileOffset, size_t rem) +namespace { +size_t calculateLength(const DiskWriterEntryHandle entry, + off_t fileOffset, size_t rem) { size_t length; if(entry->getFileEntry()->getLength() < (uint64_t)fileOffset+rem) { @@ -352,6 +357,7 @@ static size_t calculateLength(const DiskWriterEntryHandle entry, } return length; } +} // namespace namespace { class OffsetCompare { @@ -363,8 +369,8 @@ public: }; } // namespace -static DiskWriterEntries::const_iterator -findFirstDiskWriterEntry +namespace { +DiskWriterEntries::const_iterator findFirstDiskWriterEntry (const DiskWriterEntries& diskWriterEntries, off_t offset) { DiskWriterEntries::const_iterator first = @@ -381,15 +387,18 @@ findFirstDiskWriterEntry } return first; } +} // namespace -static void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e, - off_t offset) +namespace { +void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e, + off_t offset) { throw DL_ABORT_EX (StringFormat("DiskWriter for offset=%s, filename=%s is not opened.", util::itos(offset).c_str(), e->getFilePath().c_str()).str()); } +} // namespace void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len, off_t offset) diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc index 5d405a9f..7755fcd2 100644 --- a/src/MultiUrlRequestInfo.cc +++ b/src/MultiUrlRequestInfo.cc @@ -73,7 +73,8 @@ extern volatile sig_atomic_t globalHaltRequested; } // namespace global -static void handler(int signal) { +namespace { +void handler(int signal) { if( #ifdef SIGHUP signal == SIGHUP || @@ -90,6 +91,7 @@ static void handler(int signal) { } } } +} // namespace MultiUrlRequestInfo::MultiUrlRequestInfo (const std::vector<SharedHandle<RequestGroup> >& requestGroups, diff --git a/src/OptionParser.cc b/src/OptionParser.cc index a29f5225..a99b76b7 100644 --- a/src/OptionParser.cc +++ b/src/OptionParser.cc @@ -55,8 +55,9 @@ OptionParser::OptionParser(): idCounter_(0) {} +namespace { template<typename InputIterator> -static size_t countPublicOption(InputIterator first, InputIterator last) +size_t countPublicOption(InputIterator first, InputIterator last) { size_t count = 0; for(; first != last; ++first) { @@ -66,10 +67,12 @@ static size_t countPublicOption(InputIterator first, InputIterator last) } return count; } +} // namespace +namespace { template<typename InputIterator> -static void putOptions(struct option* longOpts, int* plopt, - InputIterator first, InputIterator last) +void putOptions(struct option* longOpts, int* plopt, + InputIterator first, InputIterator last) { for(; first != last; ++first) { if(!(*first)->isHidden()) { @@ -106,9 +109,11 @@ static void putOptions(struct option* longOpts, int* plopt, (*longOpts).flag = 0; (*longOpts).val = 0; } +} // namespace +namespace { template<typename InputIterator> -static std::string createOptstring(InputIterator first, InputIterator last) +std::string createOptstring(InputIterator first, InputIterator last) { std::string str = ""; for(; first != last; ++first) { @@ -125,6 +130,7 @@ static std::string createOptstring(InputIterator first, InputIterator last) } return str; } +} // namespace void OptionParser::parseArg (std::ostream& out, std::vector<std::string>& nonopts, @@ -306,8 +312,9 @@ std::vector<SharedHandle<OptionHandler> > OptionParser::findAll() const return result; } +namespace { template<typename InputIterator, typename Predicate> -static SharedHandle<OptionHandler> findOptionHandler +SharedHandle<OptionHandler> findOptionHandler (InputIterator first, InputIterator last, Predicate pred) { SharedHandle<OptionHandler> handler; @@ -317,6 +324,7 @@ static SharedHandle<OptionHandler> findOptionHandler } return handler; } +} // namespace SharedHandle<OptionHandler> OptionParser::findByName(const std::string& name) const diff --git a/src/PeerSessionResource.cc b/src/PeerSessionResource.cc index f6a8dd78..429e57a4 100644 --- a/src/PeerSessionResource.cc +++ b/src/PeerSessionResource.cc @@ -164,13 +164,15 @@ const std::vector<size_t>& PeerSessionResource::peerAllowedIndexSet() const return peerAllowedIndexSet_; } -static void updateIndexSet(std::vector<size_t>& c, size_t index) +namespace { +void updateIndexSet(std::vector<size_t>& c, size_t index) { std::vector<size_t>::iterator i = std::lower_bound(c.begin(), c.end(), index); if(i == c.end() || (*i) != index) { c.insert(i, index); } } +} // namespace void PeerSessionResource::addPeerAllowedIndex(size_t index) { diff --git a/src/PortEventPoll.cc b/src/PortEventPoll.cc index 20bf1a85..91335b15 100644 --- a/src/PortEventPoll.cc +++ b/src/PortEventPoll.cc @@ -144,7 +144,8 @@ void PortEventPoll::poll(const struct timeval& tv) // DHTEntryPoint...Command) } -static int translateEvents(EventPoll::EventType events) +namespace { +int translateEvents(EventPoll::EventType events) { int newEvents = 0; if(EventPoll::EVENT_READ&events) { @@ -161,6 +162,7 @@ static int translateEvents(EventPoll::EventType events) } return newEvents; } +} // namespace bool PortEventPoll::addEvents(sock_t socket, const PortEventPoll::KEvent& event) diff --git a/src/Request.cc b/src/Request.cc index cc1d503c..da44ea32 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -70,7 +70,8 @@ Request::Request(): connectedPort_(0) {} -static std::string removeFragment(const std::string& uri) +namespace { +std::string removeFragment(const std::string& uri) { std::string::size_type sharpIndex = uri.find("#"); if(sharpIndex == std::string::npos) { @@ -79,14 +80,10 @@ static std::string removeFragment(const std::string& uri) return uri.substr(0, sharpIndex); } } +} // namespace -static bool isHexNumber(const char c) -{ - return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || - ('a' <= c && c <= 'f'); -} - -static std::string percentEncode(const std::string& src) +namespace { +std::string percentEncode(const std::string& src) { std::string result = src; if(src.empty()) { @@ -98,7 +95,8 @@ static std::string percentEncode(const std::string& src) // '/' is not percent encoded because src is expected to be a path. if(!util::inRFC3986ReservedChars(c) && !util::inRFC3986UnreservedChars(c)) { if(c == '%') { - if(!isHexNumber(result[index+1]) || !isHexNumber(result[index+2])) { + if(!util::isHexDigit(result[index+1]) || + !util::isHexDigit(result[index+2])) { result.replace(index, 1, "%25"); } } else { @@ -109,6 +107,7 @@ static std::string percentEncode(const std::string& src) result.erase(result.size()-2); return result; } +} // namespace bool Request::setUri(const std::string& uri) { supportsPersistentConnection_ = true; diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 0cbb1df4..bba8b23c 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -164,8 +164,9 @@ SharedHandle<RequestGroup> RequestGroupMan::getRequestGroup(size_t index) const } } +namespace { template<typename Iterator> -static Iterator findByGID(Iterator first, Iterator last, gid_t gid) +Iterator findByGID(Iterator first, Iterator last, gid_t gid) { for(; first != last; ++first) { if((*first)->getGID() == gid) { @@ -174,6 +175,7 @@ static Iterator findByGID(Iterator first, Iterator last, gid_t gid) } return first; } +} // namespace SharedHandle<RequestGroup> RequestGroupMan::findRequestGroup(gid_t gid) const @@ -255,7 +257,8 @@ bool RequestGroupMan::removeReservedGroup(gid_t gid) } } -static void executeStopHook +namespace { +void executeStopHook (const SharedHandle<DownloadResult>& result, const Option* option) { if(result->result == downloadresultcode::FINISHED && @@ -271,6 +274,7 @@ static void executeStopHook util::itos(result->gid)); } } +} // namespace namespace { class ProcessStoppedRequestGroup { @@ -471,12 +475,14 @@ void RequestGroupMan::configureRequestGroup } } -static void createInitialCommand(const SharedHandle<RequestGroup>& requestGroup, - std::vector<Command*>& commands, +namespace { +void createInitialCommand(const SharedHandle<RequestGroup>& requestGroup, + std::vector<Command*>& commands, DownloadEngine* e) { requestGroup->createInitialCommand(commands, e); } +} // namespace void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e) { @@ -696,11 +702,12 @@ std::string RequestGroupMan::formatDownloadResult(const std::string& status, con return o.str(); } +namespace { template<typename StringInputIterator, typename FileEntryInputIterator> -static bool sameFilePathExists(StringInputIterator sfirst, - StringInputIterator slast, - FileEntryInputIterator ffirst, - FileEntryInputIterator flast) +bool sameFilePathExists(StringInputIterator sfirst, + StringInputIterator slast, + FileEntryInputIterator ffirst, + FileEntryInputIterator flast) { for(; ffirst != flast; ++ffirst) { if(std::binary_search(sfirst, slast, (*ffirst)->getPath())) { @@ -709,6 +716,7 @@ static bool sameFilePathExists(StringInputIterator sfirst, } return false; } +} // namespace bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) const { diff --git a/src/SelectEventPoll.cc b/src/SelectEventPoll.cc index ced1c046..9b3950fd 100644 --- a/src/SelectEventPoll.cc +++ b/src/SelectEventPoll.cc @@ -225,13 +225,15 @@ void SelectEventPoll::poll(const struct timeval& tv) } #ifdef __MINGW32__ -static void checkFdCountMingw(const fd_set& fdset, Logger* logger) +namespace { +void checkFdCountMingw(const fd_set& fdset, Logger* logger) { if(fdset.fd_count >= FD_SETSIZE) { logger->warn("The number of file descriptor exceeded FD_SETSIZE. " "Download may slow down or fail."); } } +} // namespace #endif // __MINGW32__ void SelectEventPoll::updateFdSet() diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc index 4310aa67..58335cdd 100644 --- a/src/SessionSerializer.cc +++ b/src/SessionSerializer.cc @@ -77,15 +77,18 @@ bool SessionSerializer::save(const std::string& filename) const } -static const std::vector<std::string>& getCumulativeOpts() +namespace { +const std::vector<std::string>& getCumulativeOpts() { static std::string cumulativeOpts[] = { PREF_INDEX_OUT, PREF_HEADER }; static std::vector<std::string> opts (vbegin(cumulativeOpts), vend(cumulativeOpts)); return opts; } +} // namespace -static bool inCumulativeOpts(const std::string& opt) +namespace { +bool inCumulativeOpts(const std::string& opt) { const std::vector<std::string>& cumopts = getCumulativeOpts(); for(std::vector<std::string>::const_iterator itr = cumopts.begin(), @@ -96,8 +99,10 @@ static bool inCumulativeOpts(const std::string& opt) } return false; } +} // namespace -static void writeOption(std::ostream& out, const SharedHandle<Option>& op) +namespace { +void writeOption(std::ostream& out, const SharedHandle<Option>& op) { const std::set<std::string>& requestOptions = listRequestOptions(); for(std::set<std::string>::const_iterator itr = requestOptions.begin(), @@ -123,8 +128,10 @@ static void writeOption(std::ostream& out, const SharedHandle<Option>& op) } } } +} // namespace -static void writeDownloadResult +namespace { +void writeDownloadResult (std::ostream& out, std::set<int64_t>& metainfoCache, const SharedHandle<DownloadResult>& dr) { @@ -156,6 +163,7 @@ static void writeDownloadResult } writeOption(out, dr->option); } +} // namespace void SessionSerializer::save(std::ostream& out) const { diff --git a/src/SimpleLogFormatter.cc b/src/SimpleLogFormatter.cc index fc7ee41e..f15557a1 100644 --- a/src/SimpleLogFormatter.cc +++ b/src/SimpleLogFormatter.cc @@ -49,11 +49,13 @@ SimpleLogFormatter::SimpleLogFormatter() {} SimpleLogFormatter::~SimpleLogFormatter() {} -static void writeHeader +namespace { +void writeHeader (std::ostream& o, const std::string& date, const std::string& logLevelLabel) { o << StringFormat("%s %s - ", date.c_str(), logLevelLabel.c_str()); } +} // namespace void SimpleLogFormatter::writeLog (std::ostream& o, Logger::LEVEL level, const std::string& logLevelLabel, diff --git a/src/Sqlite3CookieParser.cc b/src/Sqlite3CookieParser.cc index 0a6ae9f9..7183f57b 100644 --- a/src/Sqlite3CookieParser.cc +++ b/src/Sqlite3CookieParser.cc @@ -70,7 +70,8 @@ Sqlite3CookieParser::~Sqlite3CookieParser() sqlite3_close(db_); } -static std::string toString(const char* str) +namespace { +std::string toString(const char* str) { if(str) { return str; @@ -78,8 +79,10 @@ static std::string toString(const char* str) return A2STR::NIL; } } +} // namespace -static bool parseTime(int64_t& time, const std::string& s) +namespace { +bool parseTime(int64_t& time, const std::string& s) { if(!util::parseLLIntNoThrow(time, s)) { return false; @@ -91,9 +94,10 @@ static bool parseTime(int64_t& time, const std::string& s) } return true; } +} // namespace -static int cookieRowMapper(void* data, int columns, - char** values, char** names) +namespace { +int cookieRowMapper(void* data, int columns, char** values, char** names) { if(columns != 7) { return 0; @@ -129,6 +133,7 @@ static int cookieRowMapper(void* data, int columns, cookies.push_back(c); return 0; } +} // namespace void Sqlite3CookieParser::parse(std::vector<Cookie>& cookies) { diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index 7e7e43c4..ab9dfb02 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -197,7 +197,8 @@ SharedHandle<RequestGroup> TrackerWatcherCommand::createAnnounce() { return rg; } -static bool backupTrackerIsAvailable +namespace { +bool backupTrackerIsAvailable (const SharedHandle<DownloadContext>& context) { SharedHandle<TorrentAttribute> torrentAttrs = @@ -214,6 +215,7 @@ static bool backupTrackerIsAvailable return false; } } +} // namespace SharedHandle<RequestGroup> TrackerWatcherCommand::createRequestGroup(const std::string& uri) diff --git a/src/XML2SAXMetalinkProcessor.cc b/src/XML2SAXMetalinkProcessor.cc index c94e733f..e5ffca2a 100644 --- a/src/XML2SAXMetalinkProcessor.cc +++ b/src/XML2SAXMetalinkProcessor.cc @@ -58,7 +58,8 @@ public: }; } // namespace -static void mlStartElement +namespace { +void mlStartElement (void* userData, const xmlChar* srcLocalname, const xmlChar* srcPrefix, @@ -102,8 +103,10 @@ static void mlStartElement sd->charactersStack_.push_front(A2STR::NIL); } } +} // namespace -static void mlEndElement +namespace { +void mlEndElement (void* userData, const xmlChar* srcLocalname, const xmlChar* srcPrefix, @@ -126,16 +129,20 @@ static void mlEndElement } sd->stm_->endElement(localname, prefix, nsUri, characters); } +} // namespace -static void mlCharacters(void* userData, const xmlChar* ch, int len) +namespace { +void mlCharacters(void* userData, const xmlChar* ch, int len) { SessionData* sd = reinterpret_cast<SessionData*>(userData); if(sd->stm_->needsCharactersBuffering()) { sd->charactersStack_.front() += std::string(&ch[0], &ch[len]); } } +} // namespace -static xmlSAXHandler mySAXHandler = +namespace { +xmlSAXHandler mySAXHandler = { 0, // internalSubsetSAXFunc 0, // isStandaloneSAXFunc @@ -170,6 +177,7 @@ static xmlSAXHandler mySAXHandler = &mlEndElement, // endElementNsSAX2Func 0, // xmlStructuredErrorFunc }; +} // namespace SharedHandle<Metalinker> MetalinkProcessor::parseFile(const std::string& filename) diff --git a/src/Xml2XmlRpcRequestProcessor.cc b/src/Xml2XmlRpcRequestProcessor.cc index 498ab5c2..181b8f5d 100644 --- a/src/Xml2XmlRpcRequestProcessor.cc +++ b/src/Xml2XmlRpcRequestProcessor.cc @@ -57,8 +57,9 @@ struct SessionData { }; } // namespace -static void mlStartElement(void* userData, const xmlChar* name, - const xmlChar** attrs) +namespace { +void mlStartElement(void* userData, const xmlChar* name, + const xmlChar** attrs) { SessionData* sd = reinterpret_cast<SessionData*>(userData); std::map<std::string, std::string> attrmap; @@ -80,8 +81,10 @@ static void mlStartElement(void* userData, const xmlChar* name, sd->charactersStack_.push(std::string()); } } +} // namespace -static void mlEndElement(void* userData, const xmlChar* name) +namespace { +void mlEndElement(void* userData, const xmlChar* name) { SessionData* sd = reinterpret_cast<SessionData*>(userData); std::string characters; @@ -91,16 +94,20 @@ static void mlEndElement(void* userData, const xmlChar* name) } sd->stm_->endElement(reinterpret_cast<const char*>(name), characters); } +} // namespace -static void mlCharacters(void* userData, const xmlChar* ch, int len) +namespace { +void mlCharacters(void* userData, const xmlChar* ch, int len) { SessionData* sd = reinterpret_cast<SessionData*>(userData); if(sd->stm_->needsCharactersBuffering()) { sd->charactersStack_.top() += std::string(&ch[0], &ch[len]); } } +} // namespace -static xmlSAXHandler mySAXHandler = +namespace { +xmlSAXHandler mySAXHandler = { 0, // internalSubsetSAXFunc 0, // isStandaloneSAXFunc @@ -135,6 +142,7 @@ static xmlSAXHandler mySAXHandler = 0, // endElementNsSAX2Func 0, // xmlStructuredErrorFunc }; +} // namespace XmlRpcRequest XmlRpcRequestProcessor::parseMemory(const std::string& xml) diff --git a/src/XmlRpcMethod.cc b/src/XmlRpcMethod.cc index 56781374..9bc0c534 100644 --- a/src/XmlRpcMethod.cc +++ b/src/XmlRpcMethod.cc @@ -83,8 +83,9 @@ XmlRpcResponse XmlRpcMethod::execute } } +namespace { template<typename InputIterator> -static void gatherOption +void gatherOption (InputIterator first, InputIterator last, const std::set<std::string>& allowedOptions, const SharedHandle<Option>& option, @@ -126,6 +127,7 @@ static void gatherOption } } } +} // namespace void XmlRpcMethod::gatherRequestOption (const SharedHandle<Option>& option, const Dict* optionsDict) @@ -137,13 +139,14 @@ void XmlRpcMethod::gatherRequestOption } } +namespace { // Copy option in the range [optNameFirst, optNameLast) from src to // dest. template<typename InputIterator> -static void applyOption(InputIterator optNameFirst, - InputIterator optNameLast, - Option* dest, - Option* src) +void applyOption(InputIterator optNameFirst, + InputIterator optNameLast, + Option* dest, + Option* src) { for(; optNameFirst != optNameLast; ++optNameFirst) { if(src->defined(*optNameFirst)) { @@ -151,6 +154,7 @@ static void applyOption(InputIterator optNameFirst, } } } +} // namespace const std::set<std::string>& listChangeableOptions() { diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc index e0ba49a1..6d4ed816 100644 --- a/src/XmlRpcMethodImpl.cc +++ b/src/XmlRpcMethodImpl.cc @@ -139,12 +139,15 @@ const std::string KEY_MODE = "mode"; const std::string KEY_SERVERS = "servers"; } // namespace -static SharedHandle<ValueBase> createGIDResponse(gid_t gid) +namespace { +SharedHandle<ValueBase> createGIDResponse(gid_t gid) { return String::g(util::itos(gid)); } +} // namespace -static SharedHandle<ValueBase> +namespace { +SharedHandle<ValueBase> addRequestGroup(const SharedHandle<RequestGroup>& group, DownloadEngine* e, bool posGiven, int pos) @@ -156,8 +159,9 @@ addRequestGroup(const SharedHandle<RequestGroup>& group, } return createGIDResponse(group->getGID()); } +} // namespace -static +namespace { SharedHandle<RequestGroup> findRequestGroup(const SharedHandle<RequestGroupMan>& rgman, gid_t gid) { @@ -167,8 +171,10 @@ findRequestGroup(const SharedHandle<RequestGroupMan>& rgman, gid_t gid) } return group; } +} // namespace -static void getPosParam(const XmlRpcRequest& req, size_t posParamIndex, +namespace { +void getPosParam(const XmlRpcRequest& req, size_t posParamIndex, bool& posGiven, size_t& pos) { const Integer* p = req.getIntegerParam(posParamIndex); @@ -183,8 +189,10 @@ static void getPosParam(const XmlRpcRequest& req, size_t posParamIndex, } posGiven = false; } +} // namespace -static gid_t getRequiredGidParam +namespace { +gid_t getRequiredGidParam (const XmlRpcRequest& req, size_t posParamIndex) { const String* gidParam = req.getStringParam(posParamIndex); @@ -194,9 +202,11 @@ static gid_t getRequiredGidParam throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED); } } +} // namespace +namespace { template<typename OutputIterator> -static void extractUris(OutputIterator out, const List* src) +void extractUris(OutputIterator out, const List* src) { if(src) { for(List::ValueType::const_iterator i = src->begin(), eoi = src->end(); @@ -208,6 +218,7 @@ static void extractUris(OutputIterator out, const List* src) } } } +} // namespace SharedHandle<ValueBase> AddUriXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) @@ -302,7 +313,8 @@ SharedHandle<ValueBase> AddMetalinkXmlRpcMethod::process } #endif // ENABLE_METALINK -static SharedHandle<ValueBase> removeDownload +namespace { +SharedHandle<ValueBase> removeDownload (const XmlRpcRequest& req, DownloadEngine* e, bool forceRemove) { gid_t gid = getRequiredGidParam(req, 0); @@ -332,6 +344,7 @@ static SharedHandle<ValueBase> removeDownload } return createGIDResponse(gid); } +} // namespace SharedHandle<ValueBase> RemoveXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) @@ -345,7 +358,8 @@ SharedHandle<ValueBase> ForceRemoveXmlRpcMethod::process return removeDownload(req, e, true); } -static bool pauseRequestGroup +namespace { +bool pauseRequestGroup (const SharedHandle<RequestGroup>& group, bool reserved, bool forcePause) { if((reserved && !group->isPauseRequested()) || @@ -368,8 +382,10 @@ static bool pauseRequestGroup return false; } } +} // namespace -static SharedHandle<ValueBase> pauseDownload +namespace { +SharedHandle<ValueBase> pauseDownload (const XmlRpcRequest& req, DownloadEngine* e, bool forcePause) { gid_t gid = getRequiredGidParam(req, 0); @@ -389,6 +405,7 @@ static SharedHandle<ValueBase> pauseDownload util::itos(gid).c_str()).str()); } } +} // namespace SharedHandle<ValueBase> PauseXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) @@ -402,16 +419,19 @@ SharedHandle<ValueBase> ForcePauseXmlRpcMethod::process return pauseDownload(req, e, true); } +namespace { template<typename InputIterator> -static void pauseRequestGroups +void pauseRequestGroups (InputIterator first, InputIterator last, bool reserved, bool forcePause) { for(; first != last; ++first) { pauseRequestGroup(*first, reserved, forcePause); } } +} // namespace -static SharedHandle<ValueBase> pauseAllDownloads +namespace { +SharedHandle<ValueBase> pauseAllDownloads (const XmlRpcRequest& req, DownloadEngine* e, bool forcePause) { const std::deque<SharedHandle<RequestGroup> >& groups = @@ -423,6 +443,7 @@ static SharedHandle<ValueBase> pauseAllDownloads true, forcePause); return VLB_OK; } +} // namespace SharedHandle<ValueBase> PauseAllXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) @@ -465,8 +486,9 @@ SharedHandle<ValueBase> UnpauseAllXmlRpcMethod::process return VLB_OK; } +namespace { template<typename InputIterator> -static void createUriEntry +void createUriEntry (const SharedHandle<List>& uriList, InputIterator first, InputIterator last, const SharedHandle<String>& status) @@ -478,8 +500,10 @@ static void createUriEntry uriList->append(entry); } } +} // namespace -static void createUriEntry +namespace { +void createUriEntry (const SharedHandle<List>& uriList, const SharedHandle<FileEntry>& file) { createUriEntry(uriList, @@ -491,9 +515,11 @@ static void createUriEntry file->getRemainingUris().end(), VLB_WAITING); } +} // namespace +namespace { template<typename InputIterator> -static void createFileEntry +void createFileEntry (const SharedHandle<List>& files, InputIterator first, InputIterator last) { size_t index = 1; @@ -510,12 +536,15 @@ static void createFileEntry files->append(entry); } } +} // namespace -static bool requested_key +namespace { +bool requested_key (const std::vector<std::string>& keys, const std::string& k) { return keys.empty() || std::find(keys.begin(), keys.end(), k) != keys.end(); } +} // namespace void gatherProgressCommon (const SharedHandle<Dict>& entryDict, @@ -624,7 +653,8 @@ void gatherBitTorrentMetadata } } -static void gatherProgressBitTorrent +namespace { +void gatherProgressBitTorrent (const SharedHandle<Dict>& entryDict, const SharedHandle<TorrentAttribute>& torrentAttrs, const BtObject& btObject, @@ -651,8 +681,10 @@ static void gatherProgressBitTorrent } } } +} // namespace -static void gatherPeer +namespace { +void gatherPeer (const SharedHandle<List>& peers, const SharedHandle<PeerStorage>& ps) { std::vector<SharedHandle<Peer> > activePeers; @@ -679,9 +711,11 @@ static void gatherPeer peers->append(peerEntry); } } +} // namespace #endif // ENABLE_BITTORRENT -static void gatherProgress +namespace { +void gatherProgress (const SharedHandle<Dict>& entryDict, const SharedHandle<RequestGroup>& group, DownloadEngine* e, @@ -697,6 +731,7 @@ static void gatherProgress } #endif // ENABLE_BITTORRENT } +} // namespace void gatherStoppedDownload (const SharedHandle<Dict>& entryDict, const SharedHandle<DownloadResult>& ds, @@ -1047,8 +1082,9 @@ SharedHandle<ValueBase> GetVersionXmlRpcMethod::process return result; } +namespace { template<typename InputIterator> -static void pushRequestOption +void pushRequestOption (const SharedHandle<Dict>& dict, InputIterator optionFirst, InputIterator optionLast) { @@ -1059,6 +1095,7 @@ static void pushRequestOption } } } +} // namespace SharedHandle<ValueBase> GetOptionXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) @@ -1234,7 +1271,8 @@ SharedHandle<ValueBase> ChangeUriXmlRpcMethod::process return res; } -static SharedHandle<ValueBase> goingShutdown +namespace { +SharedHandle<ValueBase> goingShutdown (const XmlRpcRequest& req, DownloadEngine* e, bool forceHalt) { // Schedule shutdown after 3seconds to give time to client to @@ -1243,6 +1281,7 @@ static SharedHandle<ValueBase> goingShutdown LogFactory::getInstance()->info("Scheduled shutdown in 3 seconds."); return VLB_OK; } +} // namespace SharedHandle<ValueBase> ShutdownXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) diff --git a/src/XmlRpcResponse.cc b/src/XmlRpcResponse.cc index 324d219f..81b966b8 100644 --- a/src/XmlRpcResponse.cc +++ b/src/XmlRpcResponse.cc @@ -46,8 +46,9 @@ namespace aria2 { namespace xmlrpc { +namespace { template<typename OutputStream> -static void encodeValue(const SharedHandle<ValueBase>& value, OutputStream& o) +void encodeValue(const SharedHandle<ValueBase>& value, OutputStream& o) { class XmlValueBaseVisitor:public ValueBaseVisitor { private: @@ -93,9 +94,11 @@ static void encodeValue(const SharedHandle<ValueBase>& value, OutputStream& o) XmlValueBaseVisitor visitor(o); value->accept(visitor); } +} // namespace +namespace { template<typename OutputStream> -static std::string encodeAll +std::string encodeAll (OutputStream& o, int code, const SharedHandle<ValueBase>& param) { o << "<?xml version=\"1.0\"?>" << "<methodResponse>"; @@ -111,6 +114,7 @@ static std::string encodeAll o << "</methodResponse>"; return o.str(); } +} // namespace std::string XmlRpcResponse::toXml(bool gzip) const { diff --git a/src/base32.cc b/src/base32.cc index 5e1484b3..a6601975 100644 --- a/src/base32.cc +++ b/src/base32.cc @@ -39,12 +39,14 @@ namespace aria2 { namespace base32 { -static const char B32TABLE[] = { +namespace { +const char B32TABLE[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7' }; +} // namespace std::string encode(const std::string& src) { diff --git a/src/bencode2.cc b/src/bencode2.cc index 83dbd684..1075fc92 100644 --- a/src/bencode2.cc +++ b/src/bencode2.cc @@ -44,9 +44,12 @@ namespace aria2 { namespace bencode2 { -static SharedHandle<ValueBase> decodeiter(std::istream& ss, size_t depth); +namespace { +SharedHandle<ValueBase> decodeiter(std::istream& ss, size_t depth); +} // namespace -static void checkdelim(std::istream& ss, const char delim = ':') +namespace { +void checkdelim(std::istream& ss, const char delim = ':') { char d; if(!(ss.get(d) && d == delim)) { @@ -55,8 +58,10 @@ static void checkdelim(std::istream& ss, const char delim = ':') delim).str()); } } +} // namespace -static std::string decoderawstring(std::istream& ss) +namespace { +std::string decoderawstring(std::istream& ss) { int length; ss >> length; @@ -79,13 +84,17 @@ static std::string decoderawstring(std::istream& ss) } return str; } +} // namespace -static SharedHandle<ValueBase> decodestring(std::istream& ss) +namespace { +SharedHandle<ValueBase> decodestring(std::istream& ss) { return String::g(decoderawstring(ss)); } +} // namespace -static SharedHandle<ValueBase> decodeinteger(std::istream& ss) +namespace { +SharedHandle<ValueBase> decodeinteger(std::istream& ss) { Integer::ValueType iv; ss >> iv; @@ -96,8 +105,10 @@ static SharedHandle<ValueBase> decodeinteger(std::istream& ss) checkdelim(ss, 'e'); return Integer::g(iv); } +} // namespace -static SharedHandle<ValueBase> decodedict(std::istream& ss, size_t depth) +namespace { +SharedHandle<ValueBase> decodedict(std::istream& ss, size_t depth) { SharedHandle<Dict> dict = Dict::g(); char c; @@ -113,8 +124,10 @@ static SharedHandle<ValueBase> decodedict(std::istream& ss, size_t depth) throw DL_ABORT_EX("Bencode decoding failed:" " Unexpected EOF in dict context. 'e' expected."); } +} // namespace -static SharedHandle<ValueBase> decodelist(std::istream& ss, size_t depth) +namespace { +SharedHandle<ValueBase> decodelist(std::istream& ss, size_t depth) { SharedHandle<List> list = List::g(); char c; @@ -129,15 +142,19 @@ static SharedHandle<ValueBase> decodelist(std::istream& ss, size_t depth) throw DL_ABORT_EX("Bencode decoding failed:" " Unexpected EOF in list context. 'e' expected."); } +} // namespace -static void checkDepth(size_t depth) +namespace { +void checkDepth(size_t depth) { if(depth >= MAX_STRUCTURE_DEPTH) { throw DL_ABORT_EX("Bencode decoding failed: Structure is too deep."); } } +} // namespace -static SharedHandle<ValueBase> decodeiter(std::istream& ss, size_t depth) +namespace { +SharedHandle<ValueBase> decodeiter(std::istream& ss, size_t depth) { checkDepth(depth); char c; @@ -157,6 +174,7 @@ static SharedHandle<ValueBase> decodeiter(std::istream& ss, size_t depth) return decodestring(ss); } } +} // namespace SharedHandle<ValueBase> decode(std::istream& in) { diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index 17555116..2075c849 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -62,43 +62,45 @@ namespace aria2 { namespace bittorrent { -static const std::string C_NAME("name"); +namespace { +const std::string C_NAME("name"); -static const std::string C_NAME_UTF8("name.utf-8"); +const std::string C_NAME_UTF8("name.utf-8"); -static const std::string C_FILES("files"); +const std::string C_FILES("files"); -static const std::string C_LENGTH("length"); +const std::string C_LENGTH("length"); -static const std::string C_PATH("path"); +const std::string C_PATH("path"); -static const std::string C_PATH_UTF8("path.utf-8"); +const std::string C_PATH_UTF8("path.utf-8"); -static const std::string C_INFO("info"); +const std::string C_INFO("info"); -static const std::string C_PIECES("pieces"); +const std::string C_PIECES("pieces"); -static const std::string C_PIECE_LENGTH("piece length"); +const std::string C_PIECE_LENGTH("piece length"); -static const std::string C_PRIVATE("private"); +const std::string C_PRIVATE("private"); -static const std::string C_URL_LIST("url-list"); +const std::string C_URL_LIST("url-list"); -static const std::string C_ANNOUNCE("announce"); +const std::string C_ANNOUNCE("announce"); -static const std::string C_ANNOUNCE_LIST("announce-list"); +const std::string C_ANNOUNCE_LIST("announce-list"); -static const std::string C_NODES("nodes"); +const std::string C_NODES("nodes"); -static const std::string C_CREATION_DATE("creation date"); +const std::string C_CREATION_DATE("creation date"); -static const std::string C_COMMENT("comment"); +const std::string C_COMMENT("comment"); -static const std::string C_COMMENT_UTF8("comment.utf-8"); +const std::string C_COMMENT_UTF8("comment.utf-8"); -static const std::string C_CREATED_BY("created by"); +const std::string C_CREATED_BY("created by"); -static const std::string DEFAULT_PEER_ID_PREFIX("aria2-"); +const std::string DEFAULT_PEER_ID_PREFIX("aria2-"); +} // namespace const std::string BITTORRENT("bittorrent"); @@ -106,10 +108,11 @@ const std::string MULTI("multi"); const std::string SINGLE("single"); -static void extractPieceHash(const SharedHandle<DownloadContext>& ctx, - const std::string& hashData, - size_t hashLength, - size_t numPieces) +namespace { +void extractPieceHash(const SharedHandle<DownloadContext>& ctx, + const std::string& hashData, + size_t hashLength, + size_t numPieces) { std::vector<std::string> pieceHashes; pieceHashes.reserve(numPieces); @@ -120,8 +123,10 @@ static void extractPieceHash(const SharedHandle<DownloadContext>& ctx, ctx->setPieceHashes(pieceHashes.begin(), pieceHashes.end()); ctx->setPieceHashAlgo(MessageDigestContext::SHA1); } +} // namespace -static void extractUrlList +namespace { +void extractUrlList (const SharedHandle<TorrentAttribute>& torrent, std::vector<std::string>& uris, const ValueBase* v) { @@ -162,9 +167,11 @@ static void extractUrlList v->accept(visitor); } } +} // namespace +namespace { template<typename InputIterator, typename OutputIterator> -static OutputIterator createUri +OutputIterator createUri (InputIterator first, InputIterator last, OutputIterator out, const std::string& filePath) { @@ -177,8 +184,10 @@ static OutputIterator createUri } return out; } +} // namespace -static void extractFileEntries +namespace { +void extractFileEntries (const SharedHandle<DownloadContext>& ctx, const SharedHandle<TorrentAttribute>& torrent, const Dict* infoDict, @@ -308,8 +317,10 @@ static void extractFileEntries ctx->setBasePath(util::applyDir(ctx->getDir(), utf8Name)); } } +} // namespace -static void extractAnnounce +namespace { +void extractAnnounce (const SharedHandle<TorrentAttribute>& torrent, const Dict* rootDict) { const List* announceList = asList(rootDict->get(C_ANNOUNCE_LIST)); @@ -341,8 +352,10 @@ static void extractAnnounce } } } +} // namespace -static void extractNodes +namespace { +void extractNodes (const SharedHandle<TorrentAttribute>& torrent, const ValueBase* nodesListSrc) { const List* nodesList = asList(nodesListSrc); @@ -368,8 +381,10 @@ static void extractNodes } } } +} // namespace -static void processRootDictionary +namespace { +void processRootDictionary (const SharedHandle<DownloadContext>& ctx, const SharedHandle<ValueBase>& root, const std::string& defaultName, @@ -474,6 +489,7 @@ static void processRootDictionary ctx->setAttribute(BITTORRENT, torrent); } +} // namespace void load(const std::string& torrentFile, const SharedHandle<DownloadContext>& ctx, @@ -671,7 +687,9 @@ std::string generatePeerId(const std::string& peerIdPrefix) return peerId; } -static std::string peerId; +namespace { +std::string peerId; +} // namespace const std::string& generateStaticPeerId(const std::string& peerIdPrefix) { diff --git a/src/download_helper.cc b/src/download_helper.cc index 54cee855..b33c033b 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -172,7 +172,8 @@ const std::set<std::string>& listRequestOptions() return requestOptions; } -static void unfoldURI +namespace { +void unfoldURI (std::vector<std::string>& result, const std::vector<std::string>& args) { ParameterizedStringParser p; @@ -184,13 +185,15 @@ static void unfoldURI result.insert(result.end(), v.getURIs().begin(), v.getURIs().end()); } } +} // namespace +namespace { template<typename InputIterator> -static void splitURI(std::vector<std::string>& result, - InputIterator begin, - InputIterator end, - size_t numSplit, - size_t maxIter) +void splitURI(std::vector<std::string>& result, + InputIterator begin, + InputIterator end, + size_t numSplit, + size_t maxIter) { size_t numURIs = std::distance(begin, end); if(numURIs >= numSplit) { @@ -205,8 +208,10 @@ static void splitURI(std::vector<std::string>& result, } } } +} // namespace -static SharedHandle<RequestGroup> createRequestGroup +namespace { +SharedHandle<RequestGroup> createRequestGroup (const SharedHandle<Option>& option, const std::vector<std::string>& uris, bool useOutOption = false) { @@ -224,22 +229,27 @@ static SharedHandle<RequestGroup> createRequestGroup rg->setDownloadContext(dctx); return rg; } +} // namespace #if defined ENABLE_BITTORRENT || ENABLE_METALINK -static SharedHandle<MetadataInfo> createMetadataInfo(const std::string& uri) +namespace { +SharedHandle<MetadataInfo> createMetadataInfo(const std::string& uri) { return SharedHandle<MetadataInfo>(new MetadataInfo(uri)); } +} // namespace -static SharedHandle<MetadataInfo> createMetadataInfoDataOnly() +namespace { +SharedHandle<MetadataInfo> createMetadataInfoDataOnly() { return SharedHandle<MetadataInfo>(new MetadataInfo()); } +} // namespace #endif // ENABLE_BITTORRENT || ENABLE_METALINK #ifdef ENABLE_BITTORRENT -static +namespace { SharedHandle<RequestGroup> createBtRequestGroup(const std::string& torrentFilePath, const SharedHandle<Option>& option, @@ -277,8 +287,9 @@ createBtRequestGroup(const std::string& torrentFilePath, util::removeMetalinkContentTypes(rg); return rg; } +} // namespace -static +namespace { SharedHandle<RequestGroup> createBtMagnetRequestGroup(const std::string& magnetLink, const SharedHandle<Option>& option, @@ -308,6 +319,7 @@ createBtMagnetRequestGroup(const std::string& magnetLink, rg->setMetadataInfo(createMetadataInfo(magnetLink)); return rg; } +} // namespace void createRequestGroupForBitTorrent (std::vector<SharedHandle<RequestGroup> >& result, @@ -467,7 +479,8 @@ void createRequestGroupForUri } } -static void createRequestGroupForUriList +namespace { +void createRequestGroupForUriList (std::vector<SharedHandle<RequestGroup> >& result, const SharedHandle<Option>& option, std::istream& in) @@ -493,6 +506,7 @@ static void createRequestGroupForUriList createRequestGroupForUri(result, requestOption, uris); } } +} // namespace void createRequestGroupForUriList (std::vector<SharedHandle<RequestGroup> >& result, diff --git a/src/main.cc b/src/main.cc index 82d278fd..a5091e03 100644 --- a/src/main.cc +++ b/src/main.cc @@ -109,16 +109,19 @@ std::ostream& getSummaryOut(const SharedHandle<Option>& op) } #ifdef ENABLE_BITTORRENT -static void showTorrentFile(const std::string& uri) +namespace { +void showTorrentFile(const std::string& uri) { SharedHandle<DownloadContext> dctx(new DownloadContext()); bittorrent::load(uri, dctx); bittorrent::print(std::cout, dctx); } +} // namespace #endif // ENABLE_BITTORRENT #ifdef ENABLE_METALINK -static void showMetalinkFile +namespace { +void showMetalinkFile (const std::string& uri, const SharedHandle<Option>& op) { std::vector<SharedHandle<MetalinkEntry> > metalinkEntries; @@ -128,10 +131,12 @@ static void showMetalinkFile util::toStream(fileEntries.begin(), fileEntries.end(), std::cout); std::cout << std::endl; } +} // namespace #endif // ENABLE_METALINK #if defined ENABLE_BITTORRENT || defined ENABLE_METALINK -static void showFiles +namespace { +void showFiles (const std::vector<std::string>& uris, const SharedHandle<Option>& op) { ProtocolDetector dt; @@ -160,6 +165,7 @@ static void showFiles } } } +} // namespace #endif // ENABLE_BITTORRENT || ENABLE_METALINK extern void option_processing(Option& option, std::vector<std::string>& uris, diff --git a/src/messageDigest.cc b/src/messageDigest.cc index 9db9a9a3..8198d95e 100644 --- a/src/messageDigest.cc +++ b/src/messageDigest.cc @@ -56,7 +56,8 @@ struct DigestAlgoEntry { typedef std::map<std::string, DigestAlgoEntry> DigestAlgoMap; -static const DigestAlgoMap& getDigestAlgos() +namespace { +const DigestAlgoMap& getDigestAlgos() { enum AlgoStrength { STRENGTH_MD5 = 0, @@ -84,6 +85,7 @@ static const DigestAlgoMap& getDigestAlgos() static const DigestAlgoMap algomap(vbegin(digests), vend(digests)); return algomap; } +} // namespace std::string MessageDigestContext::getCanonicalAlgo (const std::string& algostring) diff --git a/src/option_processing.cc b/src/option_processing.cc index ce9c9009..831ec244 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -65,9 +65,10 @@ namespace aria2 { extern void showVersion(); extern void showUsage(const std::string& keyword, const OptionParser& oparser); -static void overrideWithEnv(Option& op, const OptionParser& optionParser, - const std::string& pref, - const std::string& envName) +namespace { +void overrideWithEnv(Option& op, const OptionParser& optionParser, + const std::string& pref, + const std::string& envName) { char* value = getenv(envName.c_str()); if(value) { @@ -81,6 +82,7 @@ static void overrideWithEnv(Option& op, const OptionParser& optionParser, } } } +} // namespace void option_processing(Option& op, std::vector<std::string>& uris, int argc, char* const argv[]) diff --git a/src/util.cc b/src/util.cc index ba46faa2..e5822b2d 100644 --- a/src/util.cc +++ b/src/util.cc @@ -413,7 +413,8 @@ std::string toHex(const std::string& src) return toHex(reinterpret_cast<const unsigned char*>(src.c_str()), src.size()); } -static unsigned int hexCharToUInt(unsigned char ch) +namespace { +unsigned int hexCharToUInt(unsigned char ch) { if('a' <= ch && ch <= 'f') { @@ -429,6 +430,7 @@ static unsigned int hexCharToUInt(unsigned char ch) } return ch; } +} // namespace std::string fromHex(const std::string& src) { @@ -634,7 +636,8 @@ IntSequence parseIntRange(const std::string& src) return values; } -static void computeHeadPieces +namespace { +void computeHeadPieces (std::vector<size_t>& indexes, const std::vector<SharedHandle<FileEntry> >& fileEntries, size_t pieceLength, @@ -656,8 +659,10 @@ static void computeHeadPieces } } } +} // namespace -static void computeTailPieces +namespace { +void computeTailPieces (std::vector<size_t>& indexes, const std::vector<SharedHandle<FileEntry> >& fileEntries, size_t pieceLength, @@ -680,6 +685,7 @@ static void computeTailPieces } } } +} // namespace void parsePrioritizePieceRange (std::vector<size_t>& result, const std::string& src, @@ -740,8 +746,9 @@ std::string iso8859ToUtf8(const std::string& src) return dest; } +namespace { template<typename OutputIterator> -static void parseParam(OutputIterator out, const std::string& header) +void parseParam(OutputIterator out, const std::string& header) { for(std::string::const_iterator i = header.begin(), eoi = header.end(); i != eoi;) { @@ -778,6 +785,7 @@ static void parseParam(OutputIterator out, const std::string& header) ++i; } } +} // namespace std::string getContentDispositionFilename(const std::string& header) { |
