mirror of https://github.com/aria2/aria2
Use fmt instead of util::itos
parent
9e5124eb11
commit
1687741303
|
@ -119,7 +119,7 @@ void DHTFindNodeReplyMessage::setClosestKNodes
|
||||||
|
|
||||||
std::string DHTFindNodeReplyMessage::toStringOptional() const
|
std::string DHTFindNodeReplyMessage::toStringOptional() const
|
||||||
{
|
{
|
||||||
return "nodes="+util::uitos(closestKNodes_.size());
|
return fmt("nodes=%lu", static_cast<unsigned long>(closestKNodes_.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -183,8 +183,8 @@ void DHTMessageFactoryImpl::validatePort(const Integer* port) const
|
||||||
{
|
{
|
||||||
if(!(0 < port->i() && port->i() < UINT16_MAX)) {
|
if(!(0 < port->i() && port->i() < UINT16_MAX)) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt("Malformed DHT message. Invalid port=%s",
|
(fmt("Malformed DHT message. Invalid port=%lld",
|
||||||
util::itos(port->i()).c_str()));
|
static_cast<long long int>(port->i())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,8 +256,8 @@ DHTMessageFactoryImpl::createResponseMessage
|
||||||
// for now, just report error message arrived and throw exception.
|
// for now, just report error message arrived and throw exception.
|
||||||
const List* e = getList(dict, DHTUnknownMessage::E);
|
const List* e = getList(dict, DHTUnknownMessage::E);
|
||||||
if(e->size() == 2) {
|
if(e->size() == 2) {
|
||||||
A2_LOG_INFO(fmt("Received Error DHT message. code=%s, msg=%s",
|
A2_LOG_INFO(fmt("Received Error DHT message. code=%lld, msg=%s",
|
||||||
util::itos(getInteger(e, 0)->i()).c_str(),
|
static_cast<long long int>(getInteger(e, 0)->i()),
|
||||||
util::percentEncode(getString(e, 1)->s()).c_str()));
|
util::percentEncode(getString(e, 1)->s()).c_str()));
|
||||||
} else {
|
} else {
|
||||||
A2_LOG_DEBUG("e doesn't have 2 elements.");
|
A2_LOG_DEBUG("e doesn't have 2 elements.");
|
||||||
|
|
|
@ -87,7 +87,7 @@ DHTMessageTracker::messageArrived
|
||||||
targetNode->getPort());
|
targetNode->getPort());
|
||||||
|
|
||||||
int64_t rtt = entry->getElapsedMillis();
|
int64_t rtt = entry->getElapsedMillis();
|
||||||
A2_LOG_DEBUG(fmt("RTT is %s", util::itos(rtt).c_str()));
|
A2_LOG_DEBUG(fmt("RTT is %lld", static_cast<long long int>(rtt)));
|
||||||
message->getRemoteNode()->updateRTT(rtt);
|
message->getRemoteNode()->updateRTT(rtt);
|
||||||
SharedHandle<DHTMessageCallback> callback = entry->getCallback();
|
SharedHandle<DHTMessageCallback> callback = entry->getCallback();
|
||||||
if(!(*targetNode == *message->getRemoteNode())) {
|
if(!(*targetNode == *message->getRemoteNode())) {
|
||||||
|
|
|
@ -144,32 +144,33 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
||||||
TransferStat stat = peerStorage_->calculateStat();
|
TransferStat stat = peerStorage_->calculateStat();
|
||||||
uint64_t left =
|
uint64_t left =
|
||||||
pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength();
|
pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength();
|
||||||
|
// Use last 8 bytes of peer ID as a key
|
||||||
|
const size_t keyLen = 8;
|
||||||
std::string uri = announceList_.getAnnounce();
|
std::string uri = announceList_.getAnnounce();
|
||||||
uri += uriHasQuery(uri) ? "&" : "?";
|
uri += uriHasQuery(uri) ? "&" : "?";
|
||||||
uri += "info_hash=";
|
uri += fmt("info_hash=%s&"
|
||||||
uri += util::torrentPercentEncode(bittorrent::getInfoHash(downloadContext_),
|
"peer_id=%s&"
|
||||||
INFO_HASH_LENGTH);
|
"uploaded=%lld&"
|
||||||
uri += "&peer_id=";
|
"downloaded=%lld&"
|
||||||
uri += util::torrentPercentEncode(bittorrent::getStaticPeerId(),
|
"left=%lld&"
|
||||||
PEER_ID_LENGTH);
|
"compact=1&"
|
||||||
uri += "&uploaded=";
|
"key=%s&"
|
||||||
uri += util::uitos(stat.getSessionUploadLength());
|
"numwant=%u&"
|
||||||
uri += "&downloaded=";
|
"no_peer_id=1",
|
||||||
uri += util::uitos(stat.getSessionDownloadLength());
|
util::torrentPercentEncode
|
||||||
uri += "&left=";
|
(bittorrent::getInfoHash(downloadContext_),
|
||||||
uri += util::uitos(left);
|
INFO_HASH_LENGTH).c_str(),
|
||||||
uri += "&compact=1";
|
util::torrentPercentEncode
|
||||||
uri += "&key=";
|
(bittorrent::getStaticPeerId(), PEER_ID_LENGTH).c_str(),
|
||||||
// Use last 8 bytes of peer ID as a key
|
static_cast<long long int>(stat.getSessionUploadLength()),
|
||||||
size_t keyLen = 8;
|
static_cast<long long int>(stat.getSessionDownloadLength()),
|
||||||
uri += util::torrentPercentEncode
|
static_cast<long long int>(left),
|
||||||
(bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen, keyLen);
|
util::torrentPercentEncode
|
||||||
uri += "&numwant=";
|
(bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen,
|
||||||
uri += util::uitos(numWant);
|
keyLen).c_str(),
|
||||||
uri += "&no_peer_id=1";
|
numWant);
|
||||||
if(tcpPort_) {
|
if(tcpPort_) {
|
||||||
uri += "&port=";
|
uri += fmt("&port=%u", tcpPort_);
|
||||||
uri += util::uitos(tcpPort_);
|
|
||||||
}
|
}
|
||||||
std::string event = announceList_.getEventString();
|
std::string event = announceList_.getEventString();
|
||||||
if(!event.empty()) {
|
if(!event.empty()) {
|
||||||
|
@ -177,7 +178,8 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
||||||
uri += event;
|
uri += event;
|
||||||
}
|
}
|
||||||
if(!trackerId_.empty()) {
|
if(!trackerId_.empty()) {
|
||||||
uri += "&trackerid="+util::torrentPercentEncode(trackerId_);
|
uri += "&trackerid=";
|
||||||
|
uri += util::torrentPercentEncode(trackerId_);
|
||||||
}
|
}
|
||||||
if(option_->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
|
if(option_->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
|
||||||
uri += "&requirecrypto=1";
|
uri += "&requirecrypto=1";
|
||||||
|
|
|
@ -277,9 +277,9 @@ void DefaultBtProgressInfoFile::load()
|
||||||
}
|
}
|
||||||
if(totalLength != dctx_->getTotalLength()) {
|
if(totalLength != dctx_->getTotalLength()) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt("total length mismatch. expected: %s, actual: %s",
|
(fmt("total length mismatch. expected: %lld, actual: %lld",
|
||||||
util::itos(dctx_->getTotalLength()).c_str(),
|
static_cast<long long int>(dctx_->getTotalLength()),
|
||||||
util::itos(totalLength).c_str()));
|
static_cast<long long int>(totalLength)));
|
||||||
}
|
}
|
||||||
uint64_t uploadLength;
|
uint64_t uploadLength;
|
||||||
READ_CHECK(fp, &uploadLength, sizeof(uploadLength));
|
READ_CHECK(fp, &uploadLength, sizeof(uploadLength));
|
||||||
|
|
|
@ -359,7 +359,7 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
|
||||||
} else {
|
} else {
|
||||||
A2_LOG_INFO(fmt(EX_INVALID_CHUNK_CHECKSUM,
|
A2_LOG_INFO(fmt(EX_INVALID_CHUNK_CHECKSUM,
|
||||||
static_cast<unsigned long>(segment->getIndex()),
|
static_cast<unsigned long>(segment->getIndex()),
|
||||||
util::itos(segment->getPosition(), true).c_str(),
|
static_cast<long long int>(segment->getPosition()),
|
||||||
util::toHex(expectedHash).c_str(),
|
util::toHex(expectedHash).c_str(),
|
||||||
util::toHex(actualHash).c_str()));
|
util::toHex(actualHash).c_str()));
|
||||||
segment->clear();
|
segment->clear();
|
||||||
|
|
|
@ -71,7 +71,7 @@ bool FileAllocationCommand::executeInternal()
|
||||||
A2_LOG_DEBUG
|
A2_LOG_DEBUG
|
||||||
(fmt(MSG_ALLOCATION_COMPLETED,
|
(fmt(MSG_ALLOCATION_COMPLETED,
|
||||||
static_cast<long int>(timer_.difference(global::wallclock())),
|
static_cast<long int>(timer_.difference(global::wallclock())),
|
||||||
util::itos(getRequestGroup()->getTotalLength(), true).c_str()));
|
static_cast<long long int>(getRequestGroup()->getTotalLength())));
|
||||||
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
|
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
|
||||||
|
|
||||||
std::vector<Command*>* commands = new std::vector<Command*>();
|
std::vector<Command*>* commands = new std::vector<Command*>();
|
||||||
|
|
|
@ -218,14 +218,11 @@ bool FtpConnection::sendEprt(const SharedHandle<SocketCore>& serverSocket)
|
||||||
serverSocket->getAddrInfo(sockaddr, len);
|
serverSocket->getAddrInfo(sockaddr, len);
|
||||||
std::pair<std::string, uint16_t> addrinfo =
|
std::pair<std::string, uint16_t> addrinfo =
|
||||||
util::getNumericNameInfo(&sockaddr.sa, len);
|
util::getNumericNameInfo(&sockaddr.sa, len);
|
||||||
std::string request = "EPRT ";
|
std::string request =
|
||||||
request += "|";
|
fmt("EPRT |%d|%s|%u|\r\n",
|
||||||
request += util::itos(sockaddr.storage.ss_family == AF_INET ? 1 : 2);
|
sockaddr.storage.ss_family == AF_INET ? 1 : 2,
|
||||||
request += "|";
|
addrinfo.first.c_str(),
|
||||||
request += addrinfo.first;
|
addrinfo.second);
|
||||||
request += "|";
|
|
||||||
request += util::uitos(addrinfo.second);
|
|
||||||
request += "|\r\n";
|
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str()));
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(request);
|
||||||
}
|
}
|
||||||
|
@ -242,19 +239,9 @@ bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
|
||||||
sscanf(addrinfo.first.c_str(), "%u.%u.%u.%u",
|
sscanf(addrinfo.first.c_str(), "%u.%u.%u.%u",
|
||||||
&ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]);
|
&ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]);
|
||||||
serverSocket->getAddrInfo(addrinfo);
|
serverSocket->getAddrInfo(addrinfo);
|
||||||
std::string request = "PORT ";
|
std::string request = fmt("PORT %u,%u,%u,%u,%u,%u\r\n",
|
||||||
request += util::uitos(ipaddr[0]);
|
ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3],
|
||||||
request += ",";
|
addrinfo.second/256, addrinfo.second%256);
|
||||||
request += util::uitos(ipaddr[1]);
|
|
||||||
request += ",";
|
|
||||||
request += util::uitos(ipaddr[2]);
|
|
||||||
request += ",";
|
|
||||||
request += util::uitos(ipaddr[3]);
|
|
||||||
request += ",";
|
|
||||||
request += util::uitos(addrinfo.second/256);
|
|
||||||
request += ",";
|
|
||||||
request += util::uitos(addrinfo.second%256);
|
|
||||||
request += "\r\n";
|
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(request);
|
||||||
|
@ -266,13 +253,10 @@ bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
|
||||||
bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
|
bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
|
||||||
{
|
{
|
||||||
if(socketBuffer_.sendBufferIsEmpty()) {
|
if(socketBuffer_.sendBufferIsEmpty()) {
|
||||||
std::string request = "REST ";
|
std::string request =
|
||||||
if(!segment) {
|
fmt("REST %lld\r\n",
|
||||||
request += "0";
|
segment ?
|
||||||
} else {
|
static_cast<long long int>(segment->getPositionToWrite()) : 0LL);
|
||||||
request += util::itos(segment->getPositionToWrite());
|
|
||||||
}
|
|
||||||
request += "\r\n";
|
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_, request.c_str()));
|
cuid_, request.c_str()));
|
||||||
socketBuffer_.pushStr(request);
|
socketBuffer_.pushStr(request);
|
||||||
|
@ -326,11 +310,7 @@ FtpConnection::findEndOfResponse(unsigned int status,
|
||||||
if(buf.at(3) == '-') {
|
if(buf.at(3) == '-') {
|
||||||
// multi line response
|
// multi line response
|
||||||
std::string::size_type p;
|
std::string::size_type p;
|
||||||
|
p = buf.find(fmt("\r\n%u ", status));
|
||||||
std::string endPattern = A2STR::CRLF;
|
|
||||||
endPattern += util::uitos(status);
|
|
||||||
endPattern += " ";
|
|
||||||
p = buf.find(endPattern);
|
|
||||||
if(p == std::string::npos) {
|
if(p == std::string::npos) {
|
||||||
return std::string::npos;
|
return std::string::npos;
|
||||||
}
|
}
|
||||||
|
@ -511,13 +491,7 @@ unsigned int FtpConnection::receivePasvResponse
|
||||||
"(%u,%u,%u,%u,%u,%u).",
|
"(%u,%u,%u,%u,%u,%u).",
|
||||||
&h1, &h2, &h3, &h4, &p1, &p2);
|
&h1, &h2, &h3, &h4, &p1, &p2);
|
||||||
// ip address
|
// ip address
|
||||||
dest.first = util::uitos(h1);
|
dest.first = fmt("%u.%u.%u.%u", h1, h2, h3, h4);
|
||||||
dest.first += A2STR::DOT_C;
|
|
||||||
dest.first += util::uitos(h2);
|
|
||||||
dest.first += A2STR::DOT_C;
|
|
||||||
dest.first += util::uitos(h3);
|
|
||||||
dest.first += A2STR::DOT_C;
|
|
||||||
dest.first += util::uitos(h4);
|
|
||||||
// port number
|
// port number
|
||||||
dest.second = 256*p1+p2;
|
dest.second = 256*p1+p2;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -471,8 +471,7 @@ bool FtpNegotiationCommand::recvSize() {
|
||||||
|
|
||||||
if(size > INT64_MAX) {
|
if(size > INT64_MAX) {
|
||||||
throw DL_ABORT_EX2
|
throw DL_ABORT_EX2
|
||||||
(fmt(EX_TOO_LARGE_FILE,
|
(fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(size)),
|
||||||
util::uitos(size, true).c_str()),
|
|
||||||
error_code::FTP_PROTOCOL_ERROR);
|
error_code::FTP_PROTOCOL_ERROR);
|
||||||
}
|
}
|
||||||
if(!getPieceStorage()) {
|
if(!getPieceStorage()) {
|
||||||
|
|
|
@ -193,9 +193,8 @@ std::string HttpRequest::createRequest()
|
||||||
}
|
}
|
||||||
if(segment_ && segment_->getLength() > 0 &&
|
if(segment_ && segment_->getLength() > 0 &&
|
||||||
(request_->isPipeliningEnabled() || getStartByte() > 0)) {
|
(request_->isPipeliningEnabled() || getStartByte() > 0)) {
|
||||||
std::string rangeHeader = "bytes=";
|
std::string rangeHeader(fmt("bytes=%lld-",
|
||||||
rangeHeader += util::itos(getStartByte());
|
static_cast<long long int>(getStartByte())));
|
||||||
rangeHeader += "-";
|
|
||||||
if(request_->isPipeliningEnabled()) {
|
if(request_->isPipeliningEnabled()) {
|
||||||
rangeHeader += util::itos(getEndByte());
|
rangeHeader += util::itos(getEndByte());
|
||||||
} else if(getProtocol() != Request::PROTO_FTP && endOffsetOverride_ > 0) {
|
} else if(getProtocol() != Request::PROTO_FTP && endOffsetOverride_ > 0) {
|
||||||
|
|
|
@ -100,12 +100,12 @@ void HttpResponse::validateResponse() const
|
||||||
if(!httpRequest_->isRangeSatisfied(responseRange)) {
|
if(!httpRequest_->isRangeSatisfied(responseRange)) {
|
||||||
throw DL_ABORT_EX2
|
throw DL_ABORT_EX2
|
||||||
(fmt(EX_INVALID_RANGE_HEADER,
|
(fmt(EX_INVALID_RANGE_HEADER,
|
||||||
util::itos(httpRequest_->getStartByte(), true).c_str(),
|
static_cast<long long int>(httpRequest_->getStartByte()),
|
||||||
util::itos(httpRequest_->getEndByte(), true).c_str(),
|
static_cast<long long int>(httpRequest_->getEndByte()),
|
||||||
util::uitos(httpRequest_->getEntityLength(), true).c_str(),
|
static_cast<long long int>(httpRequest_->getEntityLength()),
|
||||||
util::itos(responseRange->getStartByte(), true).c_str(),
|
static_cast<long long int>(responseRange->getStartByte()),
|
||||||
util::itos(responseRange->getEndByte(), true).c_str(),
|
static_cast<long long int>(responseRange->getEndByte()),
|
||||||
util::uitos(responseRange->getEntityLength(), true).c_str()),
|
static_cast<long long int>(responseRange->getEntityLength())),
|
||||||
error_code::CANNOT_RESUME);
|
error_code::CANNOT_RESUME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,10 +136,11 @@ bool HttpServerCommand::execute()
|
||||||
if(static_cast<uint64_t>
|
if(static_cast<uint64_t>
|
||||||
(e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE)) <
|
(e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE)) <
|
||||||
httpServer_->getContentLength()) {
|
httpServer_->getContentLength()) {
|
||||||
A2_LOG_INFO(fmt("Request too long. ContentLength=%s."
|
A2_LOG_INFO
|
||||||
|
(fmt("Request too long. ContentLength=%lld."
|
||||||
" See --rpc-max-request-size option to loose"
|
" See --rpc-max-request-size option to loose"
|
||||||
" this limitation.",
|
" this limitation.",
|
||||||
util::uitos(httpServer_->getContentLength()).c_str()));
|
static_cast<long long int>(httpServer_->getContentLength())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Command* command = new HttpServerBodyCommand(getCuid(), httpServer_, e_,
|
Command* command = new HttpServerBodyCommand(getCuid(), httpServer_, e_,
|
||||||
|
|
|
@ -78,7 +78,7 @@ void IteratableChunkChecksumValidator::validateChunk()
|
||||||
A2_LOG_INFO
|
A2_LOG_INFO
|
||||||
(fmt(EX_INVALID_CHUNK_CHECKSUM,
|
(fmt(EX_INVALID_CHUNK_CHECKSUM,
|
||||||
static_cast<unsigned long>(currentIndex_),
|
static_cast<unsigned long>(currentIndex_),
|
||||||
util::itos(getCurrentOffset(), true).c_str(),
|
static_cast<long long int>(getCurrentOffset()),
|
||||||
util::toHex(dctx_->getPieceHashes()[currentIndex_]).c_str(),
|
util::toHex(dctx_->getPieceHashes()[currentIndex_]).c_str(),
|
||||||
util::toHex(actualChecksum).c_str()));
|
util::toHex(actualChecksum).c_str()));
|
||||||
bitfield_->unsetBit(currentIndex_);
|
bitfield_->unsetBit(currentIndex_);
|
||||||
|
|
|
@ -348,8 +348,7 @@ DiskWriterEntries::const_iterator findFirstDiskWriterEntry
|
||||||
// In case when offset is out-of-range
|
// In case when offset is out-of-range
|
||||||
if(!isInRange(*first, offset)) {
|
if(!isInRange(*first, offset)) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt(EX_FILE_OFFSET_OUT_OF_RANGE,
|
(fmt(EX_FILE_OFFSET_OUT_OF_RANGE, static_cast<long long int>(offset)));
|
||||||
util::itos(offset, true).c_str()));
|
|
||||||
}
|
}
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
@ -360,8 +359,8 @@ void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
|
||||||
off_t offset)
|
off_t offset)
|
||||||
{
|
{
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt("DiskWriter for offset=%s, filename=%s is not opened.",
|
(fmt("DiskWriter for offset=%lld, filename=%s is not opened.",
|
||||||
util::itos(offset).c_str(),
|
static_cast<long long int>(offset),
|
||||||
e->getFilePath().c_str()));
|
e->getFilePath().c_str()));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -125,9 +125,8 @@ void IntegerRangeOptionHandler::parseArg
|
||||||
if(v < min_ || max_ < v) {
|
if(v < min_ || max_ < v) {
|
||||||
std::string msg = pref_->k;
|
std::string msg = pref_->k;
|
||||||
msg += " ";
|
msg += " ";
|
||||||
msg += _("must be between %s and %s.");
|
msg += _("must be between %d and %d.");
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX(fmt(msg.c_str(), min_, max_));
|
||||||
(fmt(msg.c_str(), util::itos(min_).c_str(), util::itos(max_).c_str()));
|
|
||||||
}
|
}
|
||||||
option.put(pref_, optarg);
|
option.put(pref_, optarg);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +134,7 @@ void IntegerRangeOptionHandler::parseArg
|
||||||
|
|
||||||
std::string IntegerRangeOptionHandler::createPossibleValuesString() const
|
std::string IntegerRangeOptionHandler::createPossibleValuesString() const
|
||||||
{
|
{
|
||||||
return util::itos(min_)+"-"+util::itos(max_);
|
return fmt("%d-%d", min_, max_);
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberOptionHandler::NumberOptionHandler
|
NumberOptionHandler::NumberOptionHandler
|
||||||
|
@ -166,15 +165,15 @@ void NumberOptionHandler::parseArg(Option& option, int64_t number)
|
||||||
std::string msg = pref_->k;
|
std::string msg = pref_->k;
|
||||||
msg += " ";
|
msg += " ";
|
||||||
if(min_ == -1 && max_ != -1) {
|
if(min_ == -1 && max_ != -1) {
|
||||||
msg += fmt(_("must be smaller than or equal to %s."),
|
msg += fmt(_("must be smaller than or equal to %lld."),
|
||||||
util::itos(max_).c_str());
|
static_cast<long long int>(max_));
|
||||||
} else if(min_ != -1 && max_ != -1) {
|
} else if(min_ != -1 && max_ != -1) {
|
||||||
msg += fmt(_("must be between %s and %s."),
|
msg += fmt(_("must be between %lld and %lld."),
|
||||||
util::itos(min_).c_str(),
|
static_cast<long long int>(min_),
|
||||||
util::itos(max_).c_str());
|
static_cast<long long int>(max_));
|
||||||
} else if(min_ != -1 && max_ == -1) {
|
} else if(min_ != -1 && max_ == -1) {
|
||||||
msg += fmt(_("must be greater than or equal to %s."),
|
msg += fmt(_("must be greater than or equal to %lld."),
|
||||||
util::itos(min_).c_str());
|
static_cast<long long int>(min_));
|
||||||
} else {
|
} else {
|
||||||
msg += _("must be a number.");
|
msg += _("must be a number.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
||||||
getDownloadEngine()->addCommand(command);
|
getDownloadEngine()->addCommand(command);
|
||||||
A2_LOG_DEBUG(fmt(MSG_INCOMING_PEER_CONNECTION,
|
A2_LOG_DEBUG(fmt(MSG_INCOMING_PEER_CONNECTION,
|
||||||
getCuid(),
|
getCuid(),
|
||||||
util::itos(getPeer()->usedBy()).c_str()));
|
getPeer()->usedBy()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -404,9 +404,9 @@ void RequestGroup::createInitialCommand
|
||||||
// truncate the file to downloadContext_->getTotalLength()
|
// truncate the file to downloadContext_->getTotalLength()
|
||||||
A2_LOG_DEBUG
|
A2_LOG_DEBUG
|
||||||
(fmt("File size not match. File is opened in writable"
|
(fmt("File size not match. File is opened in writable"
|
||||||
" mode. Expected:%s Actual:%s",
|
" mode. Expected:%lld Actual:%lld",
|
||||||
util::uitos(downloadContext_->getTotalLength()).c_str(),
|
static_cast<long long int>(downloadContext_->getTotalLength()),
|
||||||
util::uitos(actualFileSize).c_str()));
|
static_cast<long long int>(actualFileSize)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Call Load, Save and file allocation command here
|
// Call Load, Save and file allocation command here
|
||||||
|
@ -793,9 +793,7 @@ bool RequestGroup::tryAutoFileRenaming()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for(unsigned int i = 1; i < 10000; ++i) {
|
for(unsigned int i = 1; i < 10000; ++i) {
|
||||||
std::string newfilename = filepath;
|
std::string newfilename = fmt("%s.%u", filepath.c_str(), i);
|
||||||
newfilename += ".";
|
|
||||||
newfilename += util::uitos(i);
|
|
||||||
File newfile(newfilename);
|
File newfile(newfilename);
|
||||||
File ctrlfile(newfile.getPath()+DefaultBtProgressInfoFile::getSuffix());
|
File ctrlfile(newfile.getPath()+DefaultBtProgressInfoFile::getSuffix());
|
||||||
if(!newfile.exists() || (newfile.exists() && ctrlfile.exists())) {
|
if(!newfile.exists() || (newfile.exists() && ctrlfile.exists())) {
|
||||||
|
@ -917,8 +915,8 @@ void RequestGroup::validateTotalLength(uint64_t expectedTotalLength,
|
||||||
if(expectedTotalLength != actualTotalLength) {
|
if(expectedTotalLength != actualTotalLength) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt(EX_SIZE_MISMATCH,
|
(fmt(EX_SIZE_MISMATCH,
|
||||||
util::itos(expectedTotalLength, true).c_str(),
|
static_cast<long long int>(expectedTotalLength),
|
||||||
util::itos(actualTotalLength, true).c_str()));
|
static_cast<long long int>(actualTotalLength)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -470,10 +470,10 @@ size_t SegmentMan::countFreePieceFrom(size_t index) const
|
||||||
|
|
||||||
void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry)
|
void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry)
|
||||||
{
|
{
|
||||||
A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%s, length=%s",
|
A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%lld, length=%lld",
|
||||||
fileEntry->getPath().c_str(),
|
fileEntry->getPath().c_str(),
|
||||||
util::itos(fileEntry->getOffset()).c_str(),
|
static_cast<long long int>(fileEntry->getOffset()),
|
||||||
util::uitos(fileEntry->getLength()).c_str()));
|
static_cast<long long int>(fileEntry->getLength())));
|
||||||
ignoreBitfield_.addFilter(fileEntry->getOffset(), fileEntry->getLength());
|
ignoreBitfield_.addFilter(fileEntry->getOffset(), fileEntry->getLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,9 +175,8 @@ void TrackerWatcherCommand::processTrackerResponse
|
||||||
command->setPeerStorage(peerStorage_);
|
command->setPeerStorage(peerStorage_);
|
||||||
command->setPieceStorage(pieceStorage_);
|
command->setPieceStorage(pieceStorage_);
|
||||||
e_->addCommand(command);
|
e_->addCommand(command);
|
||||||
A2_LOG_DEBUG(fmt("CUID#%lld - Adding new command CUID#%s",
|
A2_LOG_DEBUG(fmt("CUID#%lld - Adding new command CUID#%lld",
|
||||||
getCuid(),
|
getCuid(), peer->usedBy()));
|
||||||
util::itos(peer->usedBy()).c_str()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@
|
||||||
"CUID#%lld - Using port %d for accepting new connections"
|
"CUID#%lld - Using port %d for accepting new connections"
|
||||||
#define MSG_BIND_FAILURE "CUID#%lld - An error occurred while binding port=%d"
|
#define MSG_BIND_FAILURE "CUID#%lld - An error occurred while binding port=%d"
|
||||||
#define MSG_INCOMING_PEER_CONNECTION \
|
#define MSG_INCOMING_PEER_CONNECTION \
|
||||||
"CUID#%lld - Incoming connection, adding new command CUID#%s"
|
"CUID#%lld - Incoming connection, adding new command CUID#%lld"
|
||||||
#define MSG_ACCEPT_FAILURE "CUID#%lld - Error in accepting connection"
|
#define MSG_ACCEPT_FAILURE "CUID#%lld - Error in accepting connection"
|
||||||
#define MSG_TRACKER_RESPONSE_PROCESSING_FAILED \
|
#define MSG_TRACKER_RESPONSE_PROCESSING_FAILED \
|
||||||
"CUID#%lld - Error occurred while processing tracker response."
|
"CUID#%lld - Error occurred while processing tracker response."
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
#define MSG_DOWNLOAD_COMPLETED _("The download was complete.")
|
#define MSG_DOWNLOAD_COMPLETED _("The download was complete.")
|
||||||
#define MSG_REMOVED_HAVE_ENTRY _("Removed %lu have entries.")
|
#define MSG_REMOVED_HAVE_ENTRY _("Removed %lu have entries.")
|
||||||
#define MSG_VALIDATING_FILE _("Validating file %s")
|
#define MSG_VALIDATING_FILE _("Validating file %s")
|
||||||
#define MSG_ALLOCATION_COMPLETED _("%ld seconds to allocate %s byte(s)")
|
#define MSG_ALLOCATION_COMPLETED "%ld seconds to allocate %lld byte(s)"
|
||||||
#define MSG_FILE_ALLOCATION_DISPATCH \
|
#define MSG_FILE_ALLOCATION_DISPATCH \
|
||||||
"Dispatching FileAllocationCommand for CUID#%lld."
|
"Dispatching FileAllocationCommand for CUID#%lld."
|
||||||
#define MSG_METALINK_QUEUEING _("Metalink: Queueing %s for download.")
|
#define MSG_METALINK_QUEUEING _("Metalink: Queueing %s for download.")
|
||||||
|
@ -207,14 +207,14 @@
|
||||||
#define EX_CONNECTION_FAILED _("Connection failed.")
|
#define EX_CONNECTION_FAILED _("Connection failed.")
|
||||||
#define EX_FILENAME_MISMATCH _("The requested filename and the previously registered one are not same. Expected:%s Actual:%s")
|
#define EX_FILENAME_MISMATCH _("The requested filename and the previously registered one are not same. Expected:%s Actual:%s")
|
||||||
#define EX_BAD_STATUS _("The response status is not successful. status=%d")
|
#define EX_BAD_STATUS _("The response status is not successful. status=%d")
|
||||||
#define EX_TOO_LARGE_FILE _("Too large file size. size=%s")
|
#define EX_TOO_LARGE_FILE "Too large file size. size=%lld"
|
||||||
#define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.")
|
#define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.")
|
||||||
#define EX_SSL_INIT_FAILURE _("SSL initialization failed: %s")
|
#define EX_SSL_INIT_FAILURE _("SSL initialization failed: %s")
|
||||||
#define EX_SSL_IO_ERROR _("SSL I/O error")
|
#define EX_SSL_IO_ERROR _("SSL I/O error")
|
||||||
#define EX_SSL_PROTOCOL_ERROR _("SSL protocol error")
|
#define EX_SSL_PROTOCOL_ERROR _("SSL protocol error")
|
||||||
#define EX_SSL_UNKNOWN_ERROR _("SSL unknown error %d")
|
#define EX_SSL_UNKNOWN_ERROR _("SSL unknown error %d")
|
||||||
#define EX_SSL_CONNECT_ERROR _("SSL initialization failed: OpenSSL connect error %d")
|
#define EX_SSL_CONNECT_ERROR _("SSL initialization failed: OpenSSL connect error %d")
|
||||||
#define EX_SIZE_MISMATCH _("Size mismatch Expected:%s Actual:%s")
|
#define EX_SIZE_MISMATCH "Size mismatch Expected:%lld Actual:%lld"
|
||||||
#define EX_AUTH_FAILED _("Authorization failed.")
|
#define EX_AUTH_FAILED _("Authorization failed.")
|
||||||
#define EX_GOT_EOF _("Got EOF from the server.")
|
#define EX_GOT_EOF _("Got EOF from the server.")
|
||||||
#define EX_EOF_FROM_PEER _("Got EOF from peer.")
|
#define EX_EOF_FROM_PEER _("Got EOF from peer.")
|
||||||
|
@ -226,7 +226,7 @@
|
||||||
#define EX_DATA_READ _("Failed to read data from disk.")
|
#define EX_DATA_READ _("Failed to read data from disk.")
|
||||||
#define EX_FILE_SHA1SUM _("Failed to calculate SHA1 digest of or a part of the file %s, cause: %s")
|
#define EX_FILE_SHA1SUM _("Failed to calculate SHA1 digest of or a part of the file %s, cause: %s")
|
||||||
#define EX_FILE_SEEK _("Failed to seek the file %s, cause: %s")
|
#define EX_FILE_SEEK _("Failed to seek the file %s, cause: %s")
|
||||||
#define EX_FILE_OFFSET_OUT_OF_RANGE _("The offset is out of range, offset=%s")
|
#define EX_FILE_OFFSET_OUT_OF_RANGE "The offset is out of range, offset=%lld"
|
||||||
#define EX_NOT_DIRECTORY _("%s is not a directory.")
|
#define EX_NOT_DIRECTORY _("%s is not a directory.")
|
||||||
#define EX_MAKE_DIR _("Failed to make the directory %s, cause: %s")
|
#define EX_MAKE_DIR _("Failed to make the directory %s, cause: %s")
|
||||||
#define EX_SEGMENT_FILE_WRITE "Failed to write into the segment file %s"
|
#define EX_SEGMENT_FILE_WRITE "Failed to write into the segment file %s"
|
||||||
|
@ -253,7 +253,7 @@
|
||||||
#define EX_INVALID_PAYLOAD_SIZE \
|
#define EX_INVALID_PAYLOAD_SIZE \
|
||||||
_("Invalid payload size for %s, size=%lu. It should be %lu.")
|
_("Invalid payload size for %s, size=%lu. It should be %lu.")
|
||||||
#define EX_INVALID_BT_MESSAGE_ID _("Invalid ID=%d for %s. It should be %d.")
|
#define EX_INVALID_BT_MESSAGE_ID _("Invalid ID=%d for %s. It should be %d.")
|
||||||
#define EX_INVALID_CHUNK_CHECKSUM _("Chunk checksum validation failed. checksumIndex=%lu, offset=%s, expectedHash=%s, actualHash=%s")
|
#define EX_INVALID_CHUNK_CHECKSUM "Chunk checksum validation failed. checksumIndex=%lu, offset=%lld, expectedHash=%s, actualHash=%s"
|
||||||
#define EX_DOWNLOAD_ABORTED _("Download aborted.")
|
#define EX_DOWNLOAD_ABORTED _("Download aborted.")
|
||||||
#define EX_DUPLICATE_FILE_DOWNLOAD _("File %s is being downloaded by other command.")
|
#define EX_DUPLICATE_FILE_DOWNLOAD _("File %s is being downloaded by other command.")
|
||||||
#define EX_INSUFFICIENT_CHECKSUM _("Insufficient checksums.")
|
#define EX_INSUFFICIENT_CHECKSUM _("Insufficient checksums.")
|
||||||
|
@ -267,7 +267,7 @@
|
||||||
#define EX_TOO_SLOW_DOWNLOAD_SPEED _("Too slow Downloading speed: %d <= %d(B/s), host:%s")
|
#define EX_TOO_SLOW_DOWNLOAD_SPEED _("Too slow Downloading speed: %d <= %d(B/s), host:%s")
|
||||||
#define EX_NO_HTTP_REQUEST_ENTRY_FOUND _("No HttpRequestEntry found.")
|
#define EX_NO_HTTP_REQUEST_ENTRY_FOUND _("No HttpRequestEntry found.")
|
||||||
#define EX_LOCATION_HEADER_REQUIRED _("Got %d status, but no location header provided.")
|
#define EX_LOCATION_HEADER_REQUIRED _("Got %d status, but no location header provided.")
|
||||||
#define EX_INVALID_RANGE_HEADER _("Invalid range header. Request: %s-%s/%s, Response: %s-%s/%s")
|
#define EX_INVALID_RANGE_HEADER "Invalid range header. Request: %lld-%lld/%lld, Response: %lld-%lld/%lld"
|
||||||
#define EX_NO_RESULT_WITH_YOUR_PREFS _("No file matched with your preference.")
|
#define EX_NO_RESULT_WITH_YOUR_PREFS _("No file matched with your preference.")
|
||||||
#define EX_EXCEPTION_CAUGHT _("Exception caught")
|
#define EX_EXCEPTION_CAUGHT _("Exception caught")
|
||||||
#define EX_TOO_LONG_PAYLOAD _("Max payload length exceeded or invalid. length = %u")
|
#define EX_TOO_LONG_PAYLOAD _("Max payload length exceeded or invalid. length = %u")
|
||||||
|
|
10
src/util.cc
10
src/util.cc
|
@ -1087,20 +1087,16 @@ std::string abbrevSize(int64_t size)
|
||||||
if(size < 1024) {
|
if(size < 1024) {
|
||||||
return itos(size, true);
|
return itos(size, true);
|
||||||
}
|
}
|
||||||
char units[] = { 'K', 'M' };
|
static const char units[] = { 'K', 'M' };
|
||||||
size_t numUnit = sizeof(units)/sizeof(char);
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
int r = size&0x3ffu;
|
int r = size&0x3ffu;
|
||||||
size >>= 10;
|
size >>= 10;
|
||||||
for(; i < numUnit-1 && size >= 1024; ++i) {
|
for(; i < sizeof(units)-1 && size >= 1024; ++i) {
|
||||||
r = size&0x3ffu;
|
r = size&0x3ffu;
|
||||||
size >>= 10;
|
size >>= 10;
|
||||||
}
|
}
|
||||||
std::string result = itos(size, true);
|
std::string result = itos(size, true);
|
||||||
result += A2STR::DOT_C;
|
result += fmt(".%d%ci", r*10/1024, units[i]);
|
||||||
result += itos(r*10/1024);
|
|
||||||
result += units[i];
|
|
||||||
result += "i";
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue