From c63af24c63d1ee8571a997c1a3b86b4e71ccd49b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 25 Sep 2012 23:28:24 +0900 Subject: [PATCH] Made BtMessage's NAME const char[] --- src/AbstractBtMessage.cc | 2 +- src/AbstractBtMessage.h | 6 +++--- src/BtAllowedFastMessage.cc | 2 +- src/BtAllowedFastMessage.h | 2 +- src/BtBitfieldMessage.cc | 2 +- src/BtBitfieldMessage.h | 2 +- src/BtCancelMessage.cc | 2 +- src/BtCancelMessage.h | 2 +- src/BtChokeMessage.cc | 2 +- src/BtChokeMessage.h | 2 +- src/BtExtendedMessage.cc | 2 +- src/BtExtendedMessage.h | 2 +- src/BtHandshakeMessage.cc | 4 ++-- src/BtHandshakeMessage.h | 2 +- src/BtHaveAllMessage.cc | 2 +- src/BtHaveAllMessage.h | 2 +- src/BtHaveMessage.cc | 2 +- src/BtHaveMessage.h | 2 +- src/BtHaveNoneMessage.cc | 2 +- src/BtHaveNoneMessage.h | 2 +- src/BtInterestedMessage.cc | 2 +- src/BtInterestedMessage.h | 2 +- src/BtKeepAliveMessage.cc | 2 +- src/BtKeepAliveMessage.h | 2 +- src/BtNotInterestedMessage.cc | 2 +- src/BtNotInterestedMessage.h | 2 +- src/BtPieceMessage.cc | 4 ++-- src/BtPieceMessage.h | 2 +- src/BtPortMessage.cc | 4 ++-- src/BtPortMessage.h | 2 +- src/BtRejectMessage.cc | 2 +- src/BtRejectMessage.h | 2 +- src/BtRequestMessage.cc | 2 +- src/BtRequestMessage.h | 2 +- src/BtSuggestPieceMessage.cc | 2 +- src/BtSuggestPieceMessage.h | 2 +- src/BtUnchokeMessage.cc | 2 +- src/BtUnchokeMessage.h | 2 +- src/IndexBtMessage.cc | 4 +--- src/IndexBtMessage.h | 2 +- src/RangeBtMessage.cc | 4 ++-- src/RangeBtMessage.h | 2 +- src/SimpleBtMessage.cc | 2 +- src/SimpleBtMessage.h | 2 +- src/ZeroBtMessage.h | 2 +- src/bittorrent_helper.cc | 13 ++++++------- src/bittorrent_helper.h | 6 +++--- 47 files changed, 60 insertions(+), 63 deletions(-) diff --git a/src/AbstractBtMessage.cc b/src/AbstractBtMessage.cc index 50d2d9c0..607f2fe3 100644 --- a/src/AbstractBtMessage.cc +++ b/src/AbstractBtMessage.cc @@ -39,7 +39,7 @@ namespace aria2 { -AbstractBtMessage::AbstractBtMessage(uint8_t id, const std::string& name) +AbstractBtMessage::AbstractBtMessage(uint8_t id, const char* name) : BtMessage(id), sendingInProgress_(false), invalidate_(false), diff --git a/src/AbstractBtMessage.h b/src/AbstractBtMessage.h index 475cace2..5d149515 100644 --- a/src/AbstractBtMessage.h +++ b/src/AbstractBtMessage.h @@ -55,7 +55,7 @@ private: bool uploading_; cuid_t cuid_; - std::string name_; + const char* name_; SharedHandle pieceStorage_; @@ -103,7 +103,7 @@ protected: return metadataGetMode_; } public: - AbstractBtMessage(uint8_t id, const std::string& name); + AbstractBtMessage(uint8_t id, const char* name); virtual ~AbstractBtMessage(); @@ -172,7 +172,7 @@ public: void setBtRequestFactory(BtRequestFactory* factory); - const std::string& getName() const + const char* getName() const { return name_; } diff --git a/src/BtAllowedFastMessage.cc b/src/BtAllowedFastMessage.cc index 1090d8f4..629b3e41 100644 --- a/src/BtAllowedFastMessage.cc +++ b/src/BtAllowedFastMessage.cc @@ -39,7 +39,7 @@ namespace aria2 { -const std::string BtAllowedFastMessage::NAME("allowed fast"); +const char BtAllowedFastMessage::NAME[] = "allowed fast"; BtAllowedFastMessage::BtAllowedFastMessage(size_t index): IndexBtMessage(ID, NAME, index) {} diff --git a/src/BtAllowedFastMessage.h b/src/BtAllowedFastMessage.h index af471f1e..aefcda8d 100644 --- a/src/BtAllowedFastMessage.h +++ b/src/BtAllowedFastMessage.h @@ -49,7 +49,7 @@ public: static const uint8_t ID = 17; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtBitfieldMessage.cc b/src/BtBitfieldMessage.cc index 6ba1d97e..f5181ed8 100644 --- a/src/BtBitfieldMessage.cc +++ b/src/BtBitfieldMessage.cc @@ -46,7 +46,7 @@ namespace aria2 { -const std::string BtBitfieldMessage::NAME("bitfield"); +const char BtBitfieldMessage::NAME[] = "bitfield"; BtBitfieldMessage::BtBitfieldMessage():SimpleBtMessage(ID, NAME), bitfield_(0), diff --git a/src/BtBitfieldMessage.h b/src/BtBitfieldMessage.h index a1c2122c..0b4dd680 100644 --- a/src/BtBitfieldMessage.h +++ b/src/BtBitfieldMessage.h @@ -56,7 +56,7 @@ public: static const uint8_t ID = 5; - static const std::string NAME; + static const char NAME[]; void setBitfield(const unsigned char* bitfield, size_t bitfieldLength); diff --git a/src/BtCancelMessage.cc b/src/BtCancelMessage.cc index 517f0cee..183291a0 100644 --- a/src/BtCancelMessage.cc +++ b/src/BtCancelMessage.cc @@ -37,7 +37,7 @@ namespace aria2 { -const std::string BtCancelMessage::NAME("cancel"); +const char BtCancelMessage::NAME[] = "cancel"; BtCancelMessage::BtCancelMessage (size_t index, int32_t begin, int32_t length) diff --git a/src/BtCancelMessage.h b/src/BtCancelMessage.h index cd8c517c..84f450ba 100644 --- a/src/BtCancelMessage.h +++ b/src/BtCancelMessage.h @@ -49,7 +49,7 @@ public: static const int8_t ID = 8; - static const std::string NAME; + static const char NAME[]; static BtCancelMessageHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtChokeMessage.cc b/src/BtChokeMessage.cc index 1a9eeede..a8956823 100644 --- a/src/BtChokeMessage.cc +++ b/src/BtChokeMessage.cc @@ -39,7 +39,7 @@ namespace aria2 { -const std::string BtChokeMessage::NAME("choke"); +const char BtChokeMessage::NAME[] = "choke"; BtChokeMessage::BtChokeMessage():ZeroBtMessage(ID, NAME) {} diff --git a/src/BtChokeMessage.h b/src/BtChokeMessage.h index a4e78a09..849dded7 100644 --- a/src/BtChokeMessage.h +++ b/src/BtChokeMessage.h @@ -49,7 +49,7 @@ public: static const uint8_t ID = 0; - static const std::string NAME; + static const char NAME[]; virtual void doReceivedAction(); diff --git a/src/BtExtendedMessage.cc b/src/BtExtendedMessage.cc index 103bd64e..7954b59c 100644 --- a/src/BtExtendedMessage.cc +++ b/src/BtExtendedMessage.cc @@ -48,7 +48,7 @@ namespace aria2 { -const std::string BtExtendedMessage::NAME("extended"); +const char BtExtendedMessage::NAME[] = "extended"; BtExtendedMessage::BtExtendedMessage (const ExtensionMessageHandle& extensionMessage): diff --git a/src/BtExtendedMessage.h b/src/BtExtendedMessage.h index 887384ec..9238083d 100644 --- a/src/BtExtendedMessage.h +++ b/src/BtExtendedMessage.h @@ -57,7 +57,7 @@ public: static const uint8_t ID = 20; - static const std::string NAME; + static const char NAME[]; static BtExtendedMessageHandle create (const SharedHandle& factory, diff --git a/src/BtHandshakeMessage.cc b/src/BtHandshakeMessage.cc index 97a3ec9b..f1968f40 100644 --- a/src/BtHandshakeMessage.cc +++ b/src/BtHandshakeMessage.cc @@ -42,7 +42,7 @@ namespace aria2 { -const std::string BtHandshakeMessage::NAME("handshake"); +const char BtHandshakeMessage::NAME[] = "handshake"; const unsigned char* BtHandshakeMessage::BT_PSTR = reinterpret_cast("BitTorrent protocol"); @@ -104,7 +104,7 @@ size_t BtHandshakeMessage::getMessageLength() { std::string BtHandshakeMessage::toString() const { return fmt("%s peerId=%s, reserved=%s", - NAME.c_str(), + NAME, util::percentEncode(peerId_, PEER_ID_LENGTH).c_str(), util::toHex(reserved_, RESERVED_LENGTH).c_str()); } diff --git a/src/BtHandshakeMessage.h b/src/BtHandshakeMessage.h index c5437908..6da8fa2d 100644 --- a/src/BtHandshakeMessage.h +++ b/src/BtHandshakeMessage.h @@ -72,7 +72,7 @@ public: static const uint8_t ID = INT8_MAX; - static const std::string NAME; + static const char NAME[]; virtual void doReceivedAction() {}; diff --git a/src/BtHaveAllMessage.cc b/src/BtHaveAllMessage.cc index fefada27..771ec342 100644 --- a/src/BtHaveAllMessage.cc +++ b/src/BtHaveAllMessage.cc @@ -41,7 +41,7 @@ namespace aria2 { -const std::string BtHaveAllMessage::NAME("have all"); +const char BtHaveAllMessage::NAME[] = "have all"; BtHaveAllMessage::BtHaveAllMessage():ZeroBtMessage(ID, NAME) {} diff --git a/src/BtHaveAllMessage.h b/src/BtHaveAllMessage.h index ad3d6cad..3af3ff11 100644 --- a/src/BtHaveAllMessage.h +++ b/src/BtHaveAllMessage.h @@ -49,7 +49,7 @@ public: static const uint8_t ID = 14; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtHaveMessage.cc b/src/BtHaveMessage.cc index 787062c8..e88643fb 100644 --- a/src/BtHaveMessage.cc +++ b/src/BtHaveMessage.cc @@ -40,7 +40,7 @@ namespace aria2 { -const std::string BtHaveMessage::NAME("have"); +const char BtHaveMessage::NAME[] = "have"; BtHaveMessage::BtHaveMessage(size_t index):IndexBtMessage(ID, NAME, index) {} diff --git a/src/BtHaveMessage.h b/src/BtHaveMessage.h index a16a38ab..1c4146fe 100644 --- a/src/BtHaveMessage.h +++ b/src/BtHaveMessage.h @@ -49,7 +49,7 @@ public: static const uint8_t ID = 4; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtHaveNoneMessage.cc b/src/BtHaveNoneMessage.cc index e88caf80..e85814de 100644 --- a/src/BtHaveNoneMessage.cc +++ b/src/BtHaveNoneMessage.cc @@ -39,7 +39,7 @@ namespace aria2 { -const std::string BtHaveNoneMessage::NAME("have none"); +const char BtHaveNoneMessage::NAME[] = "have none"; BtHaveNoneMessage::BtHaveNoneMessage():ZeroBtMessage(ID, NAME) {} diff --git a/src/BtHaveNoneMessage.h b/src/BtHaveNoneMessage.h index 45982ebb..e1ca6034 100644 --- a/src/BtHaveNoneMessage.h +++ b/src/BtHaveNoneMessage.h @@ -49,7 +49,7 @@ public: static const uint8_t ID = 15; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtInterestedMessage.cc b/src/BtInterestedMessage.cc index 0d38184f..f0b36e85 100644 --- a/src/BtInterestedMessage.cc +++ b/src/BtInterestedMessage.cc @@ -38,7 +38,7 @@ namespace aria2 { -const std::string BtInterestedMessage::NAME("interested"); +const char BtInterestedMessage::NAME[] = "interested"; BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {} diff --git a/src/BtInterestedMessage.h b/src/BtInterestedMessage.h index 30ce2fe8..740ce81a 100644 --- a/src/BtInterestedMessage.h +++ b/src/BtInterestedMessage.h @@ -53,7 +53,7 @@ public: static const uint8_t ID = 2; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtKeepAliveMessage.cc b/src/BtKeepAliveMessage.cc index 745db39c..3cb5baee 100644 --- a/src/BtKeepAliveMessage.cc +++ b/src/BtKeepAliveMessage.cc @@ -37,7 +37,7 @@ namespace aria2 { -const std::string BtKeepAliveMessage::NAME("keep alive"); +const char BtKeepAliveMessage::NAME[] = "keep alive"; unsigned char* BtKeepAliveMessage::createMessage() { diff --git a/src/BtKeepAliveMessage.h b/src/BtKeepAliveMessage.h index 7b540b36..de8e7b51 100644 --- a/src/BtKeepAliveMessage.h +++ b/src/BtKeepAliveMessage.h @@ -51,7 +51,7 @@ public: static const uint8_t ID = 99; - static const std::string NAME; + static const char NAME[]; virtual void doReceivedAction() {} diff --git a/src/BtNotInterestedMessage.cc b/src/BtNotInterestedMessage.cc index 8678a222..cf8b794a 100644 --- a/src/BtNotInterestedMessage.cc +++ b/src/BtNotInterestedMessage.cc @@ -38,7 +38,7 @@ namespace aria2 { -const std::string BtNotInterestedMessage::NAME("not interested"); +const char BtNotInterestedMessage::NAME[] = "not interested"; BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {} diff --git a/src/BtNotInterestedMessage.h b/src/BtNotInterestedMessage.h index 39e1dc06..e42948e6 100644 --- a/src/BtNotInterestedMessage.h +++ b/src/BtNotInterestedMessage.h @@ -53,7 +53,7 @@ public: static const uint8_t ID = 3; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc index 50afd684..e4c72289 100644 --- a/src/BtPieceMessage.cc +++ b/src/BtPieceMessage.cc @@ -59,7 +59,7 @@ namespace aria2 { -const std::string BtPieceMessage::NAME("piece"); +const char BtPieceMessage::NAME[] = "piece"; BtPieceMessage::BtPieceMessage (size_t index, int32_t begin, int32_t blockLength) @@ -212,7 +212,7 @@ void BtPieceMessage::pushPieceData(int64_t offset, int32_t length) const std::string BtPieceMessage::toString() const { return fmt("%s index=%lu, begin=%d, length=%d", - NAME.c_str(), + NAME, static_cast(index_), begin_, blockLength_); } diff --git a/src/BtPieceMessage.h b/src/BtPieceMessage.h index fb6ca213..c26d6855 100644 --- a/src/BtPieceMessage.h +++ b/src/BtPieceMessage.h @@ -73,7 +73,7 @@ public: static const uint8_t ID = 7; - static const std::string NAME; + static const char NAME[]; size_t getIndex() const { return index_; } diff --git a/src/BtPortMessage.cc b/src/BtPortMessage.cc index 1e1f25fb..d9bedd74 100644 --- a/src/BtPortMessage.cc +++ b/src/BtPortMessage.cc @@ -50,7 +50,7 @@ namespace aria2 { -const std::string BtPortMessage::NAME("port"); +const char BtPortMessage::NAME[] = "port"; BtPortMessage::BtPortMessage(uint16_t port) : SimpleBtMessage(ID, NAME), @@ -118,7 +118,7 @@ size_t BtPortMessage::getMessageLength() { } std::string BtPortMessage::toString() const { - return fmt("%s port=%u", NAME.c_str(), port_); + return fmt("%s port=%u", NAME, port_); } void BtPortMessage::setLocalNode(DHTNode* localNode) diff --git a/src/BtPortMessage.h b/src/BtPortMessage.h index 4dd2fe82..a3226ef3 100644 --- a/src/BtPortMessage.h +++ b/src/BtPortMessage.h @@ -61,7 +61,7 @@ public: static const uint8_t ID = 9; - static const std::string NAME; + static const char NAME[]; uint16_t getPort() const { return port_; } diff --git a/src/BtRejectMessage.cc b/src/BtRejectMessage.cc index 48bd7ba0..82afb800 100644 --- a/src/BtRejectMessage.cc +++ b/src/BtRejectMessage.cc @@ -41,7 +41,7 @@ namespace aria2 { -const std::string BtRejectMessage::NAME("reject"); +const char BtRejectMessage::NAME[] = "reject"; BtRejectMessage::BtRejectMessage (size_t index, int32_t begin, int32_t length): diff --git a/src/BtRejectMessage.h b/src/BtRejectMessage.h index 2b3139f9..8505df5a 100644 --- a/src/BtRejectMessage.h +++ b/src/BtRejectMessage.h @@ -49,7 +49,7 @@ public: static const uint8_t ID = 16; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtRequestMessage.cc b/src/BtRequestMessage.cc index dc66a41d..ea2aa1a4 100644 --- a/src/BtRequestMessage.cc +++ b/src/BtRequestMessage.cc @@ -41,7 +41,7 @@ namespace aria2 { -const std::string BtRequestMessage::NAME("request"); +const char BtRequestMessage::NAME[] = "request"; BtRequestMessage::BtRequestMessage (size_t index, int32_t begin, int32_t length, size_t blockIndex): diff --git a/src/BtRequestMessage.h b/src/BtRequestMessage.h index f64597fd..42a90d43 100644 --- a/src/BtRequestMessage.h +++ b/src/BtRequestMessage.h @@ -54,7 +54,7 @@ public: static const uint8_t ID = 6; - static const std::string NAME; + static const char NAME[]; size_t getBlockIndex() const { return blockIndex_; } void setBlockIndex(size_t blockIndex) { blockIndex_ = blockIndex; } diff --git a/src/BtSuggestPieceMessage.cc b/src/BtSuggestPieceMessage.cc index 8485486c..61caba6b 100644 --- a/src/BtSuggestPieceMessage.cc +++ b/src/BtSuggestPieceMessage.cc @@ -36,7 +36,7 @@ namespace aria2 { -const std::string BtSuggestPieceMessage::NAME("suggest piece"); +const char BtSuggestPieceMessage::NAME[] = "suggest piece"; SharedHandle BtSuggestPieceMessage::create (const unsigned char* data, size_t dataLength) diff --git a/src/BtSuggestPieceMessage.h b/src/BtSuggestPieceMessage.h index de371309..659f9ee0 100644 --- a/src/BtSuggestPieceMessage.h +++ b/src/BtSuggestPieceMessage.h @@ -49,7 +49,7 @@ public: static const uint8_t ID = 13; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/BtUnchokeMessage.cc b/src/BtUnchokeMessage.cc index 3855e802..327fd710 100644 --- a/src/BtUnchokeMessage.cc +++ b/src/BtUnchokeMessage.cc @@ -37,7 +37,7 @@ namespace aria2 { -const std::string BtUnchokeMessage::NAME("unchoke"); +const char BtUnchokeMessage::NAME[] = "unchoke"; BtUnchokeMessage::BtUnchokeMessage():ZeroBtMessage(ID, NAME) {} diff --git a/src/BtUnchokeMessage.h b/src/BtUnchokeMessage.h index 24293de1..e9229440 100644 --- a/src/BtUnchokeMessage.h +++ b/src/BtUnchokeMessage.h @@ -51,7 +51,7 @@ public: static const uint8_t ID = 1; - static const std::string NAME; + static const char NAME[]; static SharedHandle create (const unsigned char* data, size_t dataLength); diff --git a/src/IndexBtMessage.cc b/src/IndexBtMessage.cc index 8c680efd..f224d304 100644 --- a/src/IndexBtMessage.cc +++ b/src/IndexBtMessage.cc @@ -60,9 +60,7 @@ size_t IndexBtMessage::getMessageLength() std::string IndexBtMessage::toString() const { - return fmt("%s index=%lu", - getName().c_str(), - static_cast(index_)); + return fmt("%s index=%lu", getName(), static_cast(index_)); } } // namespace aria2 diff --git a/src/IndexBtMessage.h b/src/IndexBtMessage.h index 8144ac10..a685480a 100644 --- a/src/IndexBtMessage.h +++ b/src/IndexBtMessage.h @@ -56,7 +56,7 @@ protected: return message; } public: - IndexBtMessage(uint8_t id, const std::string& name, size_t index) + IndexBtMessage(uint8_t id, const char* name, size_t index) :SimpleBtMessage(id, name), index_(index) {} diff --git a/src/RangeBtMessage.cc b/src/RangeBtMessage.cc index 7791d575..eecbcc55 100644 --- a/src/RangeBtMessage.cc +++ b/src/RangeBtMessage.cc @@ -40,7 +40,7 @@ namespace aria2 { RangeBtMessage::RangeBtMessage(uint8_t id, - const std::string& name, + const char* name, size_t index, int32_t begin, int32_t length) :SimpleBtMessage(id, name), index_(index), @@ -73,7 +73,7 @@ size_t RangeBtMessage::getMessageLength() std::string RangeBtMessage::toString() const { return fmt("%s index=%lu, begin=%d, length=%d", - getName().c_str(), + getName(), static_cast(index_), begin_, length_); } diff --git a/src/RangeBtMessage.h b/src/RangeBtMessage.h index a1223085..a36c2e79 100644 --- a/src/RangeBtMessage.h +++ b/src/RangeBtMessage.h @@ -61,7 +61,7 @@ protected: return message; } public: - RangeBtMessage(uint8_t id, const std::string& name, + RangeBtMessage(uint8_t id, const char* name, size_t index, int32_t begin, int32_t length); size_t getIndex() const { return index_; } diff --git a/src/SimpleBtMessage.cc b/src/SimpleBtMessage.cc index 75a3086d..565eab29 100644 --- a/src/SimpleBtMessage.cc +++ b/src/SimpleBtMessage.cc @@ -43,7 +43,7 @@ namespace aria2 { -SimpleBtMessage::SimpleBtMessage(uint8_t id, const std::string& name) +SimpleBtMessage::SimpleBtMessage(uint8_t id, const char* name) : AbstractBtMessage(id, name) {} diff --git a/src/SimpleBtMessage.h b/src/SimpleBtMessage.h index 70db0994..c3dc6419 100644 --- a/src/SimpleBtMessage.h +++ b/src/SimpleBtMessage.h @@ -41,7 +41,7 @@ namespace aria2 { class SimpleBtMessage : public AbstractBtMessage { public: - SimpleBtMessage(uint8_t id, const std::string& name); + SimpleBtMessage(uint8_t id, const char* name); virtual void send(); diff --git a/src/ZeroBtMessage.h b/src/ZeroBtMessage.h index f719318f..f13dc995 100644 --- a/src/ZeroBtMessage.h +++ b/src/ZeroBtMessage.h @@ -54,7 +54,7 @@ protected: } public: - ZeroBtMessage(uint8_t id, const std::string& name): + ZeroBtMessage(uint8_t id, const char* name): SimpleBtMessage(id, name) {} virtual unsigned char* createMessage(); diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index e47e4143..e40cd6bf 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -847,34 +847,33 @@ std::pair unpackcompact } void assertPayloadLengthGreater -(size_t threshold, size_t actual, const std::string& msgName) +(size_t threshold, size_t actual, const char* msgName) { if(actual <= threshold) { throw DL_ABORT_EX - (fmt(MSG_TOO_SMALL_PAYLOAD_SIZE, msgName.c_str(), + (fmt(MSG_TOO_SMALL_PAYLOAD_SIZE, msgName, static_cast(actual))); } } void assertPayloadLengthEqual -(size_t expected, size_t actual, const std::string& msgName) +(size_t expected, size_t actual, const char* msgName) { if(expected != actual) { throw DL_ABORT_EX - (fmt(EX_INVALID_PAYLOAD_SIZE, msgName.c_str(), + (fmt(EX_INVALID_PAYLOAD_SIZE, msgName, static_cast(actual), static_cast(expected))); } } void assertID -(uint8_t expected, const unsigned char* data, const std::string& msgName) +(uint8_t expected, const unsigned char* data, const char* msgName) { uint8_t id = getId(data); if(expected != id) { throw DL_ABORT_EX - (fmt(EX_INVALID_BT_MESSAGE_ID, id, msgName.c_str(), - expected)); + (fmt(EX_INVALID_BT_MESSAGE_ID, id, msgName, expected)); } } diff --git a/src/bittorrent_helper.h b/src/bittorrent_helper.h index 7690d205..47ed1701 100644 --- a/src/bittorrent_helper.h +++ b/src/bittorrent_helper.h @@ -215,15 +215,15 @@ unpackcompact(const unsigned char* compact, int family); // Throws exception if threshold >= actual void assertPayloadLengthGreater -(size_t threshold, size_t actual, const std::string& msgName); +(size_t threshold, size_t actual, const char* msgName); // Throws exception if expected != actual void assertPayloadLengthEqual -(size_t expected, size_t actual, const std::string& msgName); +(size_t expected, size_t actual, const char* msgName); // Throws exception if expected is not equal to id from data. void assertID -(uint8_t expected, const unsigned char* data, const std::string& msgName); +(uint8_t expected, const unsigned char* data, const char* msgName); // Converts attrs into torrent data. This function does not guarantee // the returned string is valid torrent data.