From 795a0474df35c56307151cca5787cb8ae2df06e5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 23 Nov 2017 14:11:43 +0900 Subject: [PATCH] clang-format-5.0 --- examples/libaria2ex.cc | 9 +- src/AbstractDiskWriter.cc | 49 +-- src/ActivePeerConnectionCommand.cc | 6 +- src/AppleTLSSession.h | 2 +- src/AsyncNameResolver.h | 2 +- src/AsyncNameResolverMan.cc | 2 +- src/ChecksumCheckIntegrityEntry.cc | 5 +- src/DHTBucket.cc | 5 +- src/DHTNode.cc | 5 +- src/DHTNodeLookupEntry.h | 2 +- src/FtpConnection.cc | 6 +- src/HttpHeader.cc | 2 +- src/HttpHeader.h | 2 +- src/HttpResponseCommand.cc | 10 +- src/HttpServer.h | 4 +- src/InitiateConnectionCommandFactory.cc | 4 +- src/LibgnutlsTLSSession.cc | 6 +- src/LibsslTLSContext.cc | 9 +- src/LibuvEventPoll.cc | 2 +- src/LpdMessageDispatcher.cc | 2 +- src/MessageDigest.cc | 2 +- src/Metalink2RequestGroup.cc | 7 +- src/MetalinkParserController.cc | 2 +- src/NullWebSocketSessionMan.h | 2 +- src/OpenedFileCounter.cc | 5 +- src/OptionHandlerFactory.cc | 12 +- src/Platform.cc | 2 +- src/RpcMethodImpl.cc | 9 +- src/SSHSession.h | 2 +- src/SelectEventPoll.cc | 2 +- src/SessionSerializer.cc | 10 +- src/StreamCheckIntegrityEntry.cc | 5 +- src/TLSSession.h | 2 +- src/ValueBaseStructParserStateMachine.h | 2 +- src/WebSocketResponseCommand.cc | 4 +- src/WebSocketSessionMan.h | 2 +- src/WinTLSSession.cc | 6 +- src/console.cc | 2 +- src/util.cc | 403 ++++++++++++++++++++++-- test/ChunkedDecodingStreamFilterTest.cc | 7 +- test/HandshakeExtensionMessageTest.cc | 10 +- test/HttpRequestTest.cc | 5 +- test/IndexedListTest.cc | 2 +- test/MetalinkProcessorTest.cc | 2 +- test/PeerSessionResourceTest.cc | 5 +- test/RequestGroupManTest.cc | 79 ++--- test/RpcMethodTest.cc | 13 +- test/UriSplitTest.cc | 145 ++++----- 48 files changed, 597 insertions(+), 286 deletions(-) diff --git a/examples/libaria2ex.cc b/examples/libaria2ex.cc index 9d0ddc8c4f..f731ada2d6 100644 --- a/examples/libaria2ex.cc +++ b/examples/libaria2ex.cc @@ -128,10 +128,11 @@ int main(int argc, char** argv) if (dh) { std::cerr << " [" << aria2::gidToHex(gid) << "] " << dh->getCompletedLength() << "/" << dh->getTotalLength() - << "(" << (dh->getTotalLength() > 0 - ? (100 * dh->getCompletedLength() / - dh->getTotalLength()) - : 0) + << "(" + << (dh->getTotalLength() > 0 + ? (100 * dh->getCompletedLength() / + dh->getTotalLength()) + : 0) << "%)" << " D:" << dh->getDownloadSpeed() / 1024 << "KiB/s, U:" << dh->getUploadSpeed() / 1024 << "KiB/s" diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index bb26d010ce..a1eba628ee 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -119,7 +119,7 @@ void AbstractDiskWriter::openFile(int64_t totalLength) #else // !__MINGW32__ e.getErrNum() == ENOENT #endif // !__MINGW32__ - ) { + ) { initAndOpenFile(totalLength); } else { @@ -201,9 +201,10 @@ HANDLE openFileWithFlags(const std::string& filename, int flags, FILE_ATTRIBUTE_NORMAL, /* hTemplateFile */ 0); if (hn == INVALID_HANDLE_VALUE) { int errNum = GetLastError(); - throw DL_ABORT_EX3(errNum, fmt(EX_FILE_OPEN, filename.c_str(), - fileStrerror(errNum).c_str()), - errCode); + throw DL_ABORT_EX3( + errNum, + fmt(EX_FILE_OPEN, filename.c_str(), fileStrerror(errNum).c_str()), + errCode); } return hn; } @@ -217,9 +218,10 @@ int openFileWithFlags(const std::string& filename, int flags, ; if (fd < 0) { int errNum = errno; - throw DL_ABORT_EX3(errNum, fmt(EX_FILE_OPEN, filename.c_str(), - util::safeStrerror(errNum).c_str()), - errCode); + throw DL_ABORT_EX3( + errNum, + fmt(EX_FILE_OPEN, filename.c_str(), util::safeStrerror(errNum).c_str()), + errCode); } util::make_fd_cloexec(fd); #if defined(__APPLE__) && defined(__MACH__) @@ -454,9 +456,10 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, error_code::NOT_ENOUGH_DISK_SPACE); } else { - throw DL_ABORT_EX3(errNum, fmt(EX_FILE_WRITE, filename_.c_str(), - fileStrerror(errNum).c_str()), - error_code::FILE_IO_ERROR); + throw DL_ABORT_EX3( + errNum, + fmt(EX_FILE_WRITE, filename_.c_str(), fileStrerror(errNum).c_str()), + error_code::FILE_IO_ERROR); } } } @@ -467,9 +470,10 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, ssize_t ret; if ((ret = readDataInternal(data, len, offset)) < 0) { int errNum = fileError(); - throw DL_ABORT_EX3(errNum, fmt(EX_FILE_READ, filename_.c_str(), - fileStrerror(errNum).c_str()), - error_code::FILE_IO_ERROR); + throw DL_ABORT_EX3( + errNum, + fmt(EX_FILE_READ, filename_.c_str(), fileStrerror(errNum).c_str()), + error_code::FILE_IO_ERROR); } return ret; } @@ -526,17 +530,17 @@ void AbstractDiskWriter::allocate(int64_t offset, int64_t length, bool sparse) } #elif defined(__APPLE__) && defined(__MACH__) const auto toalloc = offset + length - size(); - fstore_t fstore = { - F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE, - 0, toalloc, 0}; + fstore_t fstore = {F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE, 0, + toalloc, 0}; if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) { // Retry non-contig. fstore.fst_flags = F_ALLOCATEALL; if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) { int err = errno; throw DL_ABORT_EX3( - err, fmt("fcntl(F_PREALLOCATE) of %" PRId64 " failed. cause: %s", - fstore.fst_length, util::safeStrerror(err).c_str()), + err, + fmt("fcntl(F_PREALLOCATE) of %" PRId64 " failed. cause: %s", + fstore.fst_length, util::safeStrerror(err).c_str()), error_code::FILE_IO_ERROR); } } @@ -559,10 +563,11 @@ void AbstractDiskWriter::allocate(int64_t offset, int64_t length, bool sparse) #elif HAVE_POSIX_FALLOCATE int r = posix_fallocate(fd_, offset, length); if (r != 0) { - throw DL_ABORT_EX3(r, fmt("posix_fallocate failed. cause: %s", - util::safeStrerror(r).c_str()), - isDiskFullError(r) ? error_code::NOT_ENOUGH_DISK_SPACE - : error_code::FILE_IO_ERROR); + throw DL_ABORT_EX3( + r, + fmt("posix_fallocate failed. cause: %s", util::safeStrerror(r).c_str()), + isDiskFullError(r) ? error_code::NOT_ENOUGH_DISK_SPACE + : error_code::FILE_IO_ERROR); } #else #error "no *_fallocate function available." diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index 2cf2441a70..7e566b4217 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -107,9 +107,9 @@ bool ActivePeerConnectionCommand::execute() int numConnection = 0; if (pieceStorage_->downloadFinished()) { if (btRuntime_->getMaxPeers() > btRuntime_->getConnections()) { - numConnection = std::min(numNewConnection_, - btRuntime_->getMaxPeers() - - btRuntime_->getConnections()); + numConnection = + std::min(numNewConnection_, btRuntime_->getMaxPeers() - + btRuntime_->getConnections()); } } else { diff --git a/src/AppleTLSSession.h b/src/AppleTLSSession.h index 5213b7b734..3fc065fc2c 100644 --- a/src/AppleTLSSession.h +++ b/src/AppleTLSSession.h @@ -128,6 +128,6 @@ class AppleTLSSession : public TLSSession { OSStatus sockWrite(const void* data, size_t* len); OSStatus sockRead(void* data, size_t* len); }; -} +} // namespace aria2 #endif // TLS_SESSION_H diff --git a/src/AsyncNameResolver.h b/src/AsyncNameResolver.h index de7113c3ad..31a6ebe94c 100644 --- a/src/AsyncNameResolver.h +++ b/src/AsyncNameResolver.h @@ -73,7 +73,7 @@ class AsyncNameResolver { , ares_addr_node* servers #endif // HAVE_ARES_ADDR_NODE - ); + ); ~AsyncNameResolver(); diff --git a/src/AsyncNameResolverMan.cc b/src/AsyncNameResolverMan.cc index ef5fb741be..be07356149 100644 --- a/src/AsyncNameResolverMan.cc +++ b/src/AsyncNameResolverMan.cc @@ -93,7 +93,7 @@ void AsyncNameResolverMan::startAsyncFamily(const std::string& hostname, , e->getAsyncDNSServers() #endif // HAVE_ARES_ADDR_NODE - ); + ); asyncNameResolver_[numResolver_]->resolve(hostname); setNameResolverCheck(numResolver_, e, command); } diff --git a/src/ChecksumCheckIntegrityEntry.cc b/src/ChecksumCheckIntegrityEntry.cc index dc225b8bae..e36a45582a 100644 --- a/src/ChecksumCheckIntegrityEntry.cc +++ b/src/ChecksumCheckIntegrityEntry.cc @@ -78,8 +78,9 @@ void ChecksumCheckIntegrityEntry::onDownloadIncomplete( std::vector>& commands, DownloadEngine* e) { if (redownload_) { - proceedFileAllocation(commands, make_unique( - getRequestGroup(), popNextCommand()), + proceedFileAllocation(commands, + make_unique( + getRequestGroup(), popNextCommand()), e); return; } diff --git a/src/DHTBucket.cc b/src/DHTBucket.cc index 5249497011..6320c26782 100644 --- a/src/DHTBucket.cc +++ b/src/DHTBucket.cc @@ -245,9 +245,8 @@ bool DHTBucket::operator==(const DHTBucket& bucket) const bool DHTBucket::needsRefresh() const { - return nodes_.size() < K || - lastUpdated_.difference(global::wallclock()) >= - DHT_BUCKET_REFRESH_INTERVAL; + return nodes_.size() < K || lastUpdated_.difference(global::wallclock()) >= + DHT_BUCKET_REFRESH_INTERVAL; } void DHTBucket::notifyUpdate() { lastUpdated_ = global::wallclock(); } diff --git a/src/DHTNode.cc b/src/DHTNode.cc index 85a5c42663..6c88d11c53 100644 --- a/src/DHTNode.cc +++ b/src/DHTNode.cc @@ -87,9 +87,8 @@ bool DHTNode::isBad() const { return condition_ >= BAD_CONDITION; } bool DHTNode::isQuestionable() const { - return !isBad() && - lastContact_.difference(global::wallclock()) >= - DHT_NODE_CONTACT_INTERVAL; + return !isBad() && lastContact_.difference(global::wallclock()) >= + DHT_NODE_CONTACT_INTERVAL; } void DHTNode::markGood() { condition_ = 0; } diff --git a/src/DHTNodeLookupEntry.h b/src/DHTNodeLookupEntry.h index 6475381b85..f7a938aa91 100644 --- a/src/DHTNodeLookupEntry.h +++ b/src/DHTNodeLookupEntry.h @@ -55,6 +55,6 @@ struct DHTNodeLookupEntry { bool operator==(const DHTNodeLookupEntry& entry) const; }; -} // namespace aria2; +} // namespace aria2 #endif // D_DHT_NODE_LOOKUP_ENTRY_H diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index febc81aaae..415b8ebd4f 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -235,9 +235,9 @@ bool FtpConnection::sendPort(const std::shared_ptr& serverSocket) bool FtpConnection::sendRest(const std::shared_ptr& segment) { if (socketBuffer_.sendBufferIsEmpty()) { - std::string request = fmt("REST %" PRId64 "\r\n", - segment ? segment->getPositionToWrite() - : static_cast(0LL)); + std::string request = + fmt("REST %" PRId64 "\r\n", segment ? segment->getPositionToWrite() + : static_cast(0LL)); A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); socketBuffer_.pushStr(std::move(request)); } diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index bcb6a9ec05..58981dd7c5 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -202,7 +202,7 @@ bool HttpHeader::fieldContains(int hdKey, const char* value) util::splitIter((*i).second.begin(), (*i).second.end(), std::back_inserter(values), ',', true // doStrip - ); + ); for (const auto& v : values) { if (util::strieq(v.first, v.second, value)) { return true; diff --git a/src/HttpHeader.h b/src/HttpHeader.h index d8e59aef74..507156354f 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -163,6 +163,6 @@ class HttpHeader { int idInterestingHeader(const char* hdName); -} // namespace +} // namespace aria2 #endif // D_HTTP_HEADER_H diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index d0e4480318..6009dc2f8b 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -279,9 +279,8 @@ bool HttpResponseCommand::executeInternal() // we ignore content-length when inflate is required fe->setLength(0); if (req->getMethod() == Request::METHOD_GET && - (totalLength != 0 || - !httpResponse->getHttpHeader()->defined( - HttpHeader::CONTENT_LENGTH))) { + (totalLength != 0 || !httpResponse->getHttpHeader()->defined( + HttpHeader::CONTENT_LENGTH))) { // DownloadContext::knowsTotalLength() == true only when // server says the size of file is 0 explicitly. getDownloadContext()->markTotalLengthIsUnknown(); @@ -422,9 +421,8 @@ bool HttpResponseCommand::handleOtherEncoding( httpResponse.get(), getContentEncodingStreamFilter(httpResponse.get())); // If chunked transfer-encoding is specified, we have to read end of // chunk markers(0\r\n\r\n, for example). - bool chunkedUsed = - streamFilter && - streamFilter->getName() == ChunkedDecodingStreamFilter::NAME; + bool chunkedUsed = streamFilter && streamFilter->getName() == + ChunkedDecodingStreamFilter::NAME; // For zero-length file, check existing file comparing its size if (!chunkedUsed && getDownloadContext()->knowsTotalLength() && diff --git a/src/HttpServer.h b/src/HttpServer.h index a958c7e5e3..7b86f03818 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -57,8 +57,8 @@ namespace util { namespace security { class HMAC; class HMACResult; -} -} +} // namespace security +} // namespace util enum RequestType { RPC_TYPE_NONE, RPC_TYPE_XML, RPC_TYPE_JSON, RPC_TYPE_JSONP }; diff --git a/src/InitiateConnectionCommandFactory.cc b/src/InitiateConnectionCommandFactory.cc index 2f864501c8..f9097680cd 100644 --- a/src/InitiateConnectionCommandFactory.cc +++ b/src/InitiateConnectionCommandFactory.cc @@ -58,7 +58,7 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand( // for SSL || req->getProtocol() == "https" #endif // ENABLE_SSL - ) { + ) { if (requestGroup->getOption()->getAsBool(PREF_ENABLE_HTTP_KEEP_ALIVE)) { req->setKeepAliveHint(true); @@ -74,7 +74,7 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand( #ifdef HAVE_LIBSSH2 || req->getProtocol() == "sftp" #endif // HAVE_LIBSSH2 - ) { + ) { if (req->getFile().empty()) { throw DL_ABORT_EX(fmt("FTP/SFTP URI %s doesn't contain file path.", req->getUri().c_str())); diff --git a/src/LibgnutlsTLSSession.cc b/src/LibgnutlsTLSSession.cc index 42f7ce0c9f..386819a2a3 100644 --- a/src/LibgnutlsTLSSession.cc +++ b/src/LibgnutlsTLSSession.cc @@ -107,9 +107,9 @@ int GnuTLSSession::init(sock_t sockfd) rv_ = gnutls_init(&sslSession_, flags); #else // GNUTLS_VERSION_NUMBER >= 0x030000 - rv_ = gnutls_init(&sslSession_, - tlsContext_->getSide() == TLS_CLIENT ? GNUTLS_CLIENT - : GNUTLS_SERVER); + rv_ = gnutls_init(&sslSession_, tlsContext_->getSide() == TLS_CLIENT + ? GNUTLS_CLIENT + : GNUTLS_SERVER); #endif // GNUTLS_VERSION_NUMBER >= 0x030000 if (rv_ != GNUTLS_E_SUCCESS) { return TLS_ERR_ERROR; diff --git a/src/LibsslTLSContext.cc b/src/LibsslTLSContext.cc index 171e498c03..62a5577d4d 100644 --- a/src/LibsslTLSContext.cc +++ b/src/LibsslTLSContext.cc @@ -125,15 +125,14 @@ OpenSSLTLSContext::OpenSSLTLSContext(TLSSessionSide side, TLSVersion minVer) }; // Disable SSLv2 and enable all workarounds for buggy servers - SSL_CTX_set_options(sslCtx_, - SSL_OP_ALL | SSL_OP_NO_SSLv2 | ver_opts + SSL_CTX_set_options(sslCtx_, SSL_OP_ALL | SSL_OP_NO_SSLv2 | ver_opts #ifdef SSL_OP_SINGLE_ECDH_USE - | SSL_OP_SINGLE_ECDH_USE + | SSL_OP_SINGLE_ECDH_USE #endif // SSL_OP_SINGLE_ECDH_USE #ifdef SSL_OP_NO_COMPRESSION - | SSL_OP_NO_COMPRESSION + | SSL_OP_NO_COMPRESSION #endif // SSL_OP_NO_COMPRESSION - ); + ); SSL_CTX_set_mode(sslCtx_, SSL_MODE_AUTO_RETRY); SSL_CTX_set_mode(sslCtx_, SSL_MODE_ENABLE_PARTIAL_WRITE); #ifdef SSL_MODE_RELEASE_BUFFERS diff --git a/src/LibuvEventPoll.cc b/src/LibuvEventPoll.cc index 3065e80439..3b877fff5d 100644 --- a/src/LibuvEventPoll.cc +++ b/src/LibuvEventPoll.cc @@ -66,7 +66,7 @@ template static void close_callback(uv_handle_t* handle) } static void timer_callback(uv_timer_t* handle) { uv_stop(handle->loop); } -} +} // namespace namespace aria2 { diff --git a/src/LpdMessageDispatcher.cc b/src/LpdMessageDispatcher.cc index 888bc80e49..cda6cc0430 100644 --- a/src/LpdMessageDispatcher.cc +++ b/src/LpdMessageDispatcher.cc @@ -121,4 +121,4 @@ std::string createLpdRequest(const std::string& multicastAddress, } // namespace bittorrent -} // namespac aria2 +} // namespace aria2 diff --git a/src/MessageDigest.cc b/src/MessageDigest.cc index 610d306e4f..60f368a853 100644 --- a/src/MessageDigest.cc +++ b/src/MessageDigest.cc @@ -61,7 +61,7 @@ HashTypeEntry hashTypes[] = { HashTypeEntry("sha-512", 5), HashTypeEntry("md5", 0), HashTypeEntry("adler32", 0), }; -} // namespace aria2 +} // namespace MessageDigest::MessageDigest(std::unique_ptr impl) : pImpl_{std::move(impl)} diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 26fa7575e4..3c564d13e6 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -139,9 +139,10 @@ void Metalink2RequestGroup::generate( const std::shared_ptr