Made BtMessage's NAME const char[]

pull/28/head
Tatsuhiro Tsujikawa 2012-09-25 23:28:24 +09:00
parent 9a510ddac0
commit c63af24c63
47 changed files with 60 additions and 63 deletions

View File

@ -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),

View File

@ -55,7 +55,7 @@ private:
bool uploading_;
cuid_t cuid_;
std::string name_;
const char* name_;
SharedHandle<PieceStorage> 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_;
}

View File

@ -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) {}

View File

@ -49,7 +49,7 @@ public:
static const uint8_t ID = 17;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtAllowedFastMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -46,7 +46,7 @@
namespace aria2 {
const std::string BtBitfieldMessage::NAME("bitfield");
const char BtBitfieldMessage::NAME[] = "bitfield";
BtBitfieldMessage::BtBitfieldMessage():SimpleBtMessage(ID, NAME),
bitfield_(0),

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -39,7 +39,7 @@
namespace aria2 {
const std::string BtChokeMessage::NAME("choke");
const char BtChokeMessage::NAME[] = "choke";
BtChokeMessage::BtChokeMessage():ZeroBtMessage(ID, NAME) {}

View File

@ -49,7 +49,7 @@ public:
static const uint8_t ID = 0;
static const std::string NAME;
static const char NAME[];
virtual void doReceivedAction();

View File

@ -48,7 +48,7 @@
namespace aria2 {
const std::string BtExtendedMessage::NAME("extended");
const char BtExtendedMessage::NAME[] = "extended";
BtExtendedMessage::BtExtendedMessage
(const ExtensionMessageHandle& extensionMessage):

View File

@ -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<ExtensionMessageFactory>& factory,

View File

@ -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<const unsigned char*>("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());
}

View File

@ -72,7 +72,7 @@ public:
static const uint8_t ID = INT8_MAX;
static const std::string NAME;
static const char NAME[];
virtual void doReceivedAction() {};

View File

@ -41,7 +41,7 @@
namespace aria2 {
const std::string BtHaveAllMessage::NAME("have all");
const char BtHaveAllMessage::NAME[] = "have all";
BtHaveAllMessage::BtHaveAllMessage():ZeroBtMessage(ID, NAME) {}

View File

@ -49,7 +49,7 @@ public:
static const uint8_t ID = 14;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtHaveAllMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -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) {}

View File

@ -49,7 +49,7 @@ public:
static const uint8_t ID = 4;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtHaveMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -39,7 +39,7 @@
namespace aria2 {
const std::string BtHaveNoneMessage::NAME("have none");
const char BtHaveNoneMessage::NAME[] = "have none";
BtHaveNoneMessage::BtHaveNoneMessage():ZeroBtMessage(ID, NAME) {}

View File

@ -49,7 +49,7 @@ public:
static const uint8_t ID = 15;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtHaveNoneMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -38,7 +38,7 @@
namespace aria2 {
const std::string BtInterestedMessage::NAME("interested");
const char BtInterestedMessage::NAME[] = "interested";
BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {}

View File

@ -53,7 +53,7 @@ public:
static const uint8_t ID = 2;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtInterestedMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -37,7 +37,7 @@
namespace aria2 {
const std::string BtKeepAliveMessage::NAME("keep alive");
const char BtKeepAliveMessage::NAME[] = "keep alive";
unsigned char* BtKeepAliveMessage::createMessage()
{

View File

@ -51,7 +51,7 @@ public:
static const uint8_t ID = 99;
static const std::string NAME;
static const char NAME[];
virtual void doReceivedAction() {}

View File

@ -38,7 +38,7 @@
namespace aria2 {
const std::string BtNotInterestedMessage::NAME("not interested");
const char BtNotInterestedMessage::NAME[] = "not interested";
BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {}

View File

@ -53,7 +53,7 @@ public:
static const uint8_t ID = 3;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtNotInterestedMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -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<unsigned long>(index_),
begin_, blockLength_);
}

View File

@ -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_; }

View File

@ -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)

View File

@ -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_; }

View File

@ -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):

View File

@ -49,7 +49,7 @@ public:
static const uint8_t ID = 16;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtRejectMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -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):

View File

@ -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; }

View File

@ -36,7 +36,7 @@
namespace aria2 {
const std::string BtSuggestPieceMessage::NAME("suggest piece");
const char BtSuggestPieceMessage::NAME[] = "suggest piece";
SharedHandle<BtSuggestPieceMessage> BtSuggestPieceMessage::create
(const unsigned char* data, size_t dataLength)

View File

@ -49,7 +49,7 @@ public:
static const uint8_t ID = 13;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtSuggestPieceMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -37,7 +37,7 @@
namespace aria2 {
const std::string BtUnchokeMessage::NAME("unchoke");
const char BtUnchokeMessage::NAME[] = "unchoke";
BtUnchokeMessage::BtUnchokeMessage():ZeroBtMessage(ID, NAME) {}

View File

@ -51,7 +51,7 @@ public:
static const uint8_t ID = 1;
static const std::string NAME;
static const char NAME[];
static SharedHandle<BtUnchokeMessage> create
(const unsigned char* data, size_t dataLength);

View File

@ -60,9 +60,7 @@ size_t IndexBtMessage::getMessageLength()
std::string IndexBtMessage::toString() const
{
return fmt("%s index=%lu",
getName().c_str(),
static_cast<unsigned long>(index_));
return fmt("%s index=%lu", getName(), static_cast<unsigned long>(index_));
}
} // namespace aria2

View File

@ -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) {}

View File

@ -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<unsigned long>(index_),
begin_, length_);
}

View File

@ -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_; }

View File

@ -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)
{}

View File

@ -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();

View File

@ -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();

View File

@ -847,34 +847,33 @@ std::pair<std::string, uint16_t> 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<unsigned long>(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<unsigned long>(actual),
static_cast<unsigned long>(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));
}
}

View File

@ -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.