mirror of https://github.com/aria2/aria2
Use fmt instead of using snprintf directly
parent
0da2468d6b
commit
5347efb967
|
@ -103,13 +103,10 @@ size_t BtHandshakeMessage::getMessageLength() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BtHandshakeMessage::toString() const {
|
std::string BtHandshakeMessage::toString() const {
|
||||||
char buf[256];
|
return fmt("%s peerId=%s, reserved=%s",
|
||||||
snprintf(buf, sizeof(buf),
|
|
||||||
"%s peerId=%s, reserved=%s",
|
|
||||||
NAME.c_str(),
|
NAME.c_str(),
|
||||||
util::percentEncode(peerId_, PEER_ID_LENGTH).c_str(),
|
util::percentEncode(peerId_, PEER_ID_LENGTH).c_str(),
|
||||||
util::toHex(reserved_, RESERVED_LENGTH).c_str());
|
util::toHex(reserved_, RESERVED_LENGTH).c_str());
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BtHandshakeMessage::isFastExtensionSupported() const {
|
bool BtHandshakeMessage::isFastExtensionSupported() const {
|
||||||
|
|
|
@ -213,13 +213,11 @@ void BtPieceMessage::pushPieceData(off_t offset, size_t length) const
|
||||||
|
|
||||||
std::string BtPieceMessage::toString() const
|
std::string BtPieceMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("%s index=%lu, begin=%u, length=%lu",
|
||||||
snprintf(buf, sizeof(buf), "%s index=%lu, begin=%u, length=%lu",
|
|
||||||
NAME.c_str(),
|
NAME.c_str(),
|
||||||
static_cast<unsigned long>(index_),
|
static_cast<unsigned long>(index_),
|
||||||
begin_,
|
begin_,
|
||||||
static_cast<unsigned long>(blockLength_));
|
static_cast<unsigned long>(blockLength_));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
|
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
|
||||||
|
|
|
@ -118,9 +118,7 @@ size_t BtPortMessage::getMessageLength() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BtPortMessage::toString() const {
|
std::string BtPortMessage::toString() const {
|
||||||
char buf[256];
|
return fmt("%s port=%u", NAME.c_str(), port_);
|
||||||
snprintf(buf, sizeof(buf), "%s port=%u", NAME.c_str(), port_);
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtPortMessage::setLocalNode(DHTNode* localNode)
|
void BtPortMessage::setLocalNode(DHTNode* localNode)
|
||||||
|
|
|
@ -129,13 +129,10 @@ void DHTAnnouncePeerMessage::setTokenTracker(DHTTokenTracker* tokenTracker)
|
||||||
|
|
||||||
std::string DHTAnnouncePeerMessage::toStringOptional() const
|
std::string DHTAnnouncePeerMessage::toStringOptional() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("token=%s, info_hash=%s, tcpPort=%u",
|
||||||
snprintf(buf, sizeof(buf),
|
|
||||||
"token=%s, info_hash=%s, tcpPort=%u",
|
|
||||||
util::toHex(token_).c_str(),
|
util::toHex(token_).c_str(),
|
||||||
util::toHex(infoHash_, INFO_HASH_LENGTH).c_str(),
|
util::toHex(infoHash_, INFO_HASH_LENGTH).c_str(),
|
||||||
tcpPort_);
|
tcpPort_);
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -158,13 +158,10 @@ void DHTGetPeersReplyMessage::accept(DHTMessageCallback* callback)
|
||||||
|
|
||||||
std::string DHTGetPeersReplyMessage::toStringOptional() const
|
std::string DHTGetPeersReplyMessage::toStringOptional() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("token=%s, values=%lu, nodes=%lu",
|
||||||
snprintf(buf, sizeof(buf),
|
|
||||||
"token=%s, values=%lu, nodes=%lu",
|
|
||||||
util::toHex(token_).c_str(),
|
util::toHex(token_).c_str(),
|
||||||
static_cast<unsigned long>(values_.size()),
|
static_cast<unsigned long>(values_.size()),
|
||||||
static_cast<unsigned long>(closestKNodes_.size()));
|
static_cast<unsigned long>(closestKNodes_.size()));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -117,15 +117,12 @@ void DHTNode::timeout()
|
||||||
|
|
||||||
std::string DHTNode::toString() const
|
std::string DHTNode::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("DHTNode ID=%s, Host=%s(%u), Condition=%u, RTT=%u",
|
||||||
snprintf(buf, sizeof(buf),
|
|
||||||
"DHTNode ID=%s, Host=%s(%u), Condition=%u, RTT=%u",
|
|
||||||
util::toHex(id_, DHT_ID_LENGTH).c_str(),
|
util::toHex(id_, DHT_ID_LENGTH).c_str(),
|
||||||
ipaddr_.c_str(),
|
ipaddr_.c_str(),
|
||||||
port_,
|
port_,
|
||||||
condition_,
|
condition_,
|
||||||
rtt_);
|
rtt_);
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTNode::setID(const unsigned char* id)
|
void DHTNode::setID(const unsigned char* id)
|
||||||
|
|
|
@ -68,9 +68,7 @@ bool DHTQueryMessage::isReply() const
|
||||||
|
|
||||||
std::string DHTQueryMessage::toString() const
|
std::string DHTQueryMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("dht query %s TransactionID=%s Remote:%s(%u), id=%s, v=%s, %s",
|
||||||
snprintf(buf, sizeof(buf),
|
|
||||||
"dht query %s TransactionID=%s Remote:%s(%u), id=%s, v=%s, %s",
|
|
||||||
getMessageType().c_str(),
|
getMessageType().c_str(),
|
||||||
util::toHex(getTransactionID()).c_str(),
|
util::toHex(getTransactionID()).c_str(),
|
||||||
getRemoteNode()->getIPAddress().c_str(),
|
getRemoteNode()->getIPAddress().c_str(),
|
||||||
|
@ -78,7 +76,6 @@ std::string DHTQueryMessage::toString() const
|
||||||
util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH).c_str(),
|
util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH).c_str(),
|
||||||
util::torrentPercentEncode(getVersion()).c_str(),
|
util::torrentPercentEncode(getVersion()).c_str(),
|
||||||
toStringOptional().c_str());
|
toStringOptional().c_str());
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -65,9 +65,7 @@ bool DHTResponseMessage::isReply() const
|
||||||
|
|
||||||
std::string DHTResponseMessage::toString() const
|
std::string DHTResponseMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("dht response %s TransactionID=%s Remote:%s(%u), id=%s, v=%s, %s",
|
||||||
snprintf(buf, sizeof(buf),
|
|
||||||
"dht response %s TransactionID=%s Remote:%s(%u), id=%s, v=%s, %s",
|
|
||||||
getMessageType().c_str(),
|
getMessageType().c_str(),
|
||||||
util::toHex(getTransactionID()).c_str(),
|
util::toHex(getTransactionID()).c_str(),
|
||||||
getRemoteNode()->getIPAddress().c_str(),
|
getRemoteNode()->getIPAddress().c_str(),
|
||||||
|
@ -75,7 +73,6 @@ std::string DHTResponseMessage::toString() const
|
||||||
util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH).c_str(),
|
util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH).c_str(),
|
||||||
util::torrentPercentEncode(getVersion()).c_str(),
|
util::torrentPercentEncode(getVersion()).c_str(),
|
||||||
toStringOptional().c_str());
|
toStringOptional().c_str());
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -88,14 +88,10 @@ std::string DHTUnknownMessage::toString() const
|
||||||
if(length_ < sampleLength) {
|
if(length_ < sampleLength) {
|
||||||
sampleLength = length_;
|
sampleLength = length_;
|
||||||
}
|
}
|
||||||
std::string sample(&data_[0], &data_[sampleLength]);
|
return fmt("dht unknown Remote:%s(%u) length=%lu, first 8 bytes(hex)=%s",
|
||||||
char buf[256];
|
|
||||||
snprintf(buf, sizeof(buf),
|
|
||||||
"dht unknown Remote:%s(%u) length=%lu, first 8 bytes(hex)=%s",
|
|
||||||
ipaddr_.c_str(), port_,
|
ipaddr_.c_str(), port_,
|
||||||
static_cast<unsigned long>(length_),
|
static_cast<unsigned long>(length_),
|
||||||
util::toHex(data_, sampleLength).c_str());
|
util::toHex(data_, sampleLength).c_str());
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -724,10 +724,8 @@ bool FtpNegotiationCommand::sendTunnelRequest()
|
||||||
SharedHandle<Request> req(new Request());
|
SharedHandle<Request> req(new Request());
|
||||||
// Construct fake URI in order to use HttpRequest
|
// Construct fake URI in order to use HttpRequest
|
||||||
// TODO Handle IPv6 address; it must be enclosed with [].
|
// TODO Handle IPv6 address; it must be enclosed with [].
|
||||||
char fakeUriBuf[1024];
|
req->setUri(fmt("ftp://%s:%u",
|
||||||
snprintf(fakeUriBuf, sizeof(fakeUriBuf), "ftp://%s:%u",
|
dataConnAddr_.first.c_str(), dataConnAddr_.second));
|
||||||
dataConnAddr_.first.c_str(), dataConnAddr_.second);
|
|
||||||
req->setUri(fakeUriBuf);
|
|
||||||
httpRequest->setRequest(req);
|
httpRequest->setRequest(req);
|
||||||
httpRequest->setProxyRequest(createProxyRequest());
|
httpRequest->setProxyRequest(createProxyRequest());
|
||||||
http_->sendProxyRequest(httpRequest);
|
http_->sendProxyRequest(httpRequest);
|
||||||
|
|
|
@ -60,11 +60,9 @@ size_t IndexBtMessage::getMessageLength()
|
||||||
|
|
||||||
std::string IndexBtMessage::toString() const
|
std::string IndexBtMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("%s index=%lu",
|
||||||
snprintf(buf, sizeof(buf), "%s index=%lu",
|
|
||||||
getName().c_str(),
|
getName().c_str(),
|
||||||
static_cast<unsigned long>(index_));
|
static_cast<unsigned long>(index_));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -262,17 +262,13 @@ std::string FloatNumberOptionHandler::createPossibleValuesString() const
|
||||||
if(min_ < 0) {
|
if(min_ < 0) {
|
||||||
valuesString += "*";
|
valuesString += "*";
|
||||||
} else {
|
} else {
|
||||||
char buf[11];
|
valuesString += fmt("%.1f", min_);
|
||||||
snprintf(buf, sizeof(buf), "%.1f", min_);
|
|
||||||
valuesString += buf;
|
|
||||||
}
|
}
|
||||||
valuesString += "-";
|
valuesString += "-";
|
||||||
if(max_ < 0) {
|
if(max_ < 0) {
|
||||||
valuesString += "*";
|
valuesString += "*";
|
||||||
} else {
|
} else {
|
||||||
char buf[11];
|
valuesString += fmt("%.1f", max_);
|
||||||
snprintf(buf, sizeof(buf), "%.1f", max_);
|
|
||||||
valuesString += buf;
|
|
||||||
}
|
}
|
||||||
return valuesString;
|
return valuesString;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,11 +167,9 @@ bool Piece::getAllMissingBlockIndexes
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Piece::toString() const {
|
std::string Piece::toString() const {
|
||||||
char buf[256];
|
return fmt("piece: index=%lu, length=%lu",
|
||||||
snprintf(buf, sizeof(buf), "piece: index=%lu, length=%lu",
|
|
||||||
static_cast<unsigned long>(index_),
|
static_cast<unsigned long>(index_),
|
||||||
static_cast<unsigned long>(length_));
|
static_cast<unsigned long>(length_));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Piece::reconfigure(size_t length)
|
void Piece::reconfigure(size_t length)
|
||||||
|
|
|
@ -72,14 +72,11 @@ size_t RangeBtMessage::getMessageLength()
|
||||||
|
|
||||||
std::string RangeBtMessage::toString() const
|
std::string RangeBtMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("%s index=%lu, begin=%u, length=%lu",
|
||||||
snprintf(buf, sizeof(buf),
|
|
||||||
"%s index=%lu, begin=%u, length=%lu",
|
|
||||||
getName().c_str(),
|
getName().c_str(),
|
||||||
static_cast<unsigned long>(index_),
|
static_cast<unsigned long>(index_),
|
||||||
begin_,
|
begin_,
|
||||||
static_cast<unsigned long>(length_));
|
static_cast<unsigned long>(length_));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -71,10 +71,8 @@ std::string UTMetadataDataExtensionMessage::getPayload()
|
||||||
|
|
||||||
std::string UTMetadataDataExtensionMessage::toString() const
|
std::string UTMetadataDataExtensionMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("ut_metadata data piece=%lu",
|
||||||
snprintf(buf, sizeof(buf), "ut_metadata data piece=%lu",
|
|
||||||
static_cast<unsigned long>(getIndex()));
|
static_cast<unsigned long>(getIndex()));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UTMetadataDataExtensionMessage::doReceivedAction()
|
void UTMetadataDataExtensionMessage::doReceivedAction()
|
||||||
|
|
|
@ -54,10 +54,8 @@ std::string UTMetadataRejectExtensionMessage::getPayload()
|
||||||
|
|
||||||
std::string UTMetadataRejectExtensionMessage::toString() const
|
std::string UTMetadataRejectExtensionMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("ut_metadata reject piece=%lu",
|
||||||
snprintf(buf, sizeof(buf), "ut_metadata reject piece=%lu",
|
|
||||||
static_cast<unsigned long>(getIndex()));
|
static_cast<unsigned long>(getIndex()));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UTMetadataRejectExtensionMessage::doReceivedAction()
|
void UTMetadataRejectExtensionMessage::doReceivedAction()
|
||||||
|
|
|
@ -69,10 +69,8 @@ std::string UTMetadataRequestExtensionMessage::getPayload()
|
||||||
|
|
||||||
std::string UTMetadataRequestExtensionMessage::toString() const
|
std::string UTMetadataRequestExtensionMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("ut_metadata request piece=%lu",
|
||||||
snprintf(buf, sizeof(buf), "ut_metadata request piece=%lu",
|
|
||||||
static_cast<unsigned long>(getIndex()));
|
static_cast<unsigned long>(getIndex()));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UTMetadataRequestExtensionMessage::doReceivedAction()
|
void UTMetadataRequestExtensionMessage::doReceivedAction()
|
||||||
|
|
|
@ -121,11 +121,9 @@ UTPexExtensionMessage::createCompactPeerListAndFlag
|
||||||
|
|
||||||
std::string UTPexExtensionMessage::toString() const
|
std::string UTPexExtensionMessage::toString() const
|
||||||
{
|
{
|
||||||
char buf[256];
|
return fmt("ut_pex added=%lu, dropped=%lu",
|
||||||
snprintf(buf, sizeof(buf), "ut_pex added=%lu, dropped=%lu",
|
|
||||||
static_cast<unsigned long>(freshPeers_.size()),
|
static_cast<unsigned long>(freshPeers_.size()),
|
||||||
static_cast<unsigned long>(droppedPeers_.size()));
|
static_cast<unsigned long>(droppedPeers_.size()));
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UTPexExtensionMessage::doReceivedAction()
|
void UTPexExtensionMessage::doReceivedAction()
|
||||||
|
|
Loading…
Reference in New Issue