From f0000a87544fde9beb3d38fa979f02ce001c7efe Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 26 Sep 2012 00:01:41 +0900 Subject: [PATCH] Made ExtensionMessage's NAME const char[] --- src/ExtensionMessage.h | 4 ++-- src/HandshakeExtensionMessage.cc | 7 +++---- src/HandshakeExtensionMessage.h | 4 ++-- src/UTMetadataExtensionMessage.cc | 2 +- src/UTMetadataExtensionMessage.h | 4 ++-- src/UTPexExtensionMessage.cc | 4 ++-- src/UTPexExtensionMessage.h | 4 ++-- test/HandshakeExtensionMessageTest.cc | 3 ++- test/MockExtensionMessage.h | 4 ++-- test/UTMetadataRequestExtensionMessageTest.cc | 3 ++- test/UTPexExtensionMessageTest.cc | 3 ++- 11 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/ExtensionMessage.h b/src/ExtensionMessage.h index 17ec102d..6fc5012a 100644 --- a/src/ExtensionMessage.h +++ b/src/ExtensionMessage.h @@ -49,8 +49,8 @@ public: virtual std::string getPayload() = 0; virtual uint8_t getExtensionMessageID() = 0; - - virtual const std::string& getExtensionName() const = 0; + + virtual const char* getExtensionName() const = 0; virtual std::string toString() const = 0; diff --git a/src/HandshakeExtensionMessage.cc b/src/HandshakeExtensionMessage.cc index 4a9c065c..e0860d2a 100644 --- a/src/HandshakeExtensionMessage.cc +++ b/src/HandshakeExtensionMessage.cc @@ -49,7 +49,7 @@ namespace aria2 { -const std::string HandshakeExtensionMessage::EXTENSION_NAME = "handshake"; +const char HandshakeExtensionMessage::EXTENSION_NAME[] = "handshake"; HandshakeExtensionMessage::HandshakeExtensionMessage() : tcpPort_(0), @@ -83,7 +83,7 @@ std::string HandshakeExtensionMessage::getPayload() std::string HandshakeExtensionMessage::toString() const { std::string s(fmt("%s client=%s, tcpPort=%u, metadataSize=%lu", - getExtensionName().c_str(), + getExtensionName(), util::percentEncode(clientVersion_).c_str(), tcpPort_, static_cast(metadataSize_))); @@ -162,8 +162,7 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length) if(length < 1) { throw DL_ABORT_EX (fmt(MSG_TOO_SMALL_PAYLOAD_SIZE, - EXTENSION_NAME.c_str(), - static_cast(length))); + EXTENSION_NAME, static_cast(length))); } HandshakeExtensionMessageHandle msg(new HandshakeExtensionMessage()); A2_LOG_DEBUG(fmt("Creating HandshakeExtensionMessage from %s", diff --git a/src/HandshakeExtensionMessage.h b/src/HandshakeExtensionMessage.h index f5650cff..50e353ba 100644 --- a/src/HandshakeExtensionMessage.h +++ b/src/HandshakeExtensionMessage.h @@ -71,12 +71,12 @@ public: return 0; } - virtual const std::string& getExtensionName() const + virtual const char* getExtensionName() const { return EXTENSION_NAME; } - static const std::string EXTENSION_NAME; + static const char EXTENSION_NAME[]; virtual std::string toString() const; diff --git a/src/UTMetadataExtensionMessage.cc b/src/UTMetadataExtensionMessage.cc index 737e47ae..292efdb7 100644 --- a/src/UTMetadataExtensionMessage.cc +++ b/src/UTMetadataExtensionMessage.cc @@ -36,7 +36,7 @@ namespace aria2 { -const std::string UTMetadataExtensionMessage::EXTENSION_NAME = "ut_metadata"; +const char UTMetadataExtensionMessage::EXTENSION_NAME[] = "ut_metadata"; UTMetadataExtensionMessage::UTMetadataExtensionMessage (uint8_t extensionMessageID): diff --git a/src/UTMetadataExtensionMessage.h b/src/UTMetadataExtensionMessage.h index 4fa47f7e..9b3d6a47 100644 --- a/src/UTMetadataExtensionMessage.h +++ b/src/UTMetadataExtensionMessage.h @@ -52,12 +52,12 @@ public: return extensionMessageID_; } - virtual const std::string& getExtensionName() const + virtual const char* getExtensionName() const { return EXTENSION_NAME; } - static const std::string EXTENSION_NAME; + static const char EXTENSION_NAME[]; void setIndex(size_t index) { diff --git a/src/UTPexExtensionMessage.cc b/src/UTPexExtensionMessage.cc index 4b64be47..a2573030 100644 --- a/src/UTPexExtensionMessage.cc +++ b/src/UTPexExtensionMessage.cc @@ -55,7 +55,7 @@ const size_t DEFAULT_MAX_DROPPED_PEER = 50; } // namespace -const std::string UTPexExtensionMessage::EXTENSION_NAME = "ut_pex"; +const char UTPexExtensionMessage::EXTENSION_NAME[] = "ut_pex"; UTPexExtensionMessage::UTPexExtensionMessage(uint8_t extensionMessageID): extensionMessageID_(extensionMessageID), @@ -186,7 +186,7 @@ UTPexExtensionMessage::create(const unsigned char* data, size_t len) { if(len < 1) { throw DL_ABORT_EX(fmt(MSG_TOO_SMALL_PAYLOAD_SIZE, - EXTENSION_NAME.c_str(), + EXTENSION_NAME, static_cast(len))); } UTPexExtensionMessageHandle msg(new UTPexExtensionMessage(*data)); diff --git a/src/UTPexExtensionMessage.h b/src/UTPexExtensionMessage.h index 85eb1dc7..7bc2393a 100644 --- a/src/UTPexExtensionMessage.h +++ b/src/UTPexExtensionMessage.h @@ -81,12 +81,12 @@ public: return extensionMessageID_; } - virtual const std::string& getExtensionName() const + virtual const char* getExtensionName() const { return EXTENSION_NAME; } - static const std::string EXTENSION_NAME; + static const char EXTENSION_NAME[]; virtual std::string toString() const; diff --git a/test/HandshakeExtensionMessageTest.cc b/test/HandshakeExtensionMessageTest.cc index 4c17038a..064a006e 100644 --- a/test/HandshakeExtensionMessageTest.cc +++ b/test/HandshakeExtensionMessageTest.cc @@ -51,7 +51,8 @@ void HandshakeExtensionMessageTest::testGetExtensionMessageID() void HandshakeExtensionMessageTest::testGetExtensionName() { HandshakeExtensionMessage msg; - CPPUNIT_ASSERT_EQUAL(std::string("handshake"), msg.getExtensionName()); + CPPUNIT_ASSERT_EQUAL(std::string("handshake"), + std::string(msg.getExtensionName())); } void HandshakeExtensionMessageTest::testGetBencodedData() diff --git a/test/MockExtensionMessage.h b/test/MockExtensionMessage.h index 5ab3a76e..232de21b 100644 --- a/test/MockExtensionMessage.h +++ b/test/MockExtensionMessage.h @@ -40,9 +40,9 @@ public: return extensionMessageID_; } - virtual const std::string& getExtensionName() const + virtual const char* getExtensionName() const { - return extensionName_; + return extensionName_.c_str(); } virtual std::string toString() const diff --git a/test/UTMetadataRequestExtensionMessageTest.cc b/test/UTMetadataRequestExtensionMessageTest.cc index 427bce5a..34a07f8e 100644 --- a/test/UTMetadataRequestExtensionMessageTest.cc +++ b/test/UTMetadataRequestExtensionMessageTest.cc @@ -78,7 +78,8 @@ void UTMetadataRequestExtensionMessageTest::testGetExtensionMessageID() void UTMetadataRequestExtensionMessageTest::testGetExtensionName() { UTMetadataRequestExtensionMessage msg(1); - CPPUNIT_ASSERT_EQUAL(std::string("ut_metadata"), msg.getExtensionName()); + CPPUNIT_ASSERT_EQUAL(std::string("ut_metadata"), + std::string(msg.getExtensionName())); } void UTMetadataRequestExtensionMessageTest::testGetBencodedData() diff --git a/test/UTPexExtensionMessageTest.cc b/test/UTPexExtensionMessageTest.cc index 00913de8..fe67d3ab 100644 --- a/test/UTPexExtensionMessageTest.cc +++ b/test/UTPexExtensionMessageTest.cc @@ -63,7 +63,8 @@ void UTPexExtensionMessageTest::testGetExtensionMessageID() void UTPexExtensionMessageTest::testGetExtensionName() { UTPexExtensionMessage msg(1); - CPPUNIT_ASSERT_EQUAL(std::string("ut_pex"), msg.getExtensionName()); + CPPUNIT_ASSERT_EQUAL(std::string("ut_pex"), + std::string(msg.getExtensionName())); } void UTPexExtensionMessageTest::testGetBencodedData()