mirror of https://github.com/aria2/aria2
2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
urlencode -> percentEncode, torrentUrlencode -> torrentPercentEncode * src/BtHandshakeMessage.cc * src/BtHandshakeMessageValidator.h * src/DHTMessageFactoryImpl.cc * src/DefaultBtAnnounce.cc * src/HandshakeExtensionMessage.cc * src/HttpRequest.cc * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/util.cc * src/util.h * test/DHTAnnouncePeerMessageTest.cc * test/DHTGetPeersMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/UTPexExtensionMessageTest.cc * test/UtilTest.ccpull/1/head
parent
4785b7190c
commit
10b52bd9ac
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
urlencode -> percentEncode,
|
||||
torrentUrlencode -> torrentPercentEncode
|
||||
* src/BtHandshakeMessage.cc
|
||||
* src/BtHandshakeMessageValidator.h
|
||||
* src/DHTMessageFactoryImpl.cc
|
||||
* src/DefaultBtAnnounce.cc
|
||||
* src/HandshakeExtensionMessage.cc
|
||||
* src/HttpRequest.cc
|
||||
* src/XmlRpcMethodImpl.cc
|
||||
* src/bittorrent_helper.cc
|
||||
* src/util.cc
|
||||
* src/util.h
|
||||
* test/DHTAnnouncePeerMessageTest.cc
|
||||
* test/DHTGetPeersMessageTest.cc
|
||||
* test/DHTGetPeersReplyMessageTest.cc
|
||||
* test/UTPexExtensionMessageTest.cc
|
||||
* test/UtilTest.cc
|
||||
|
||||
2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Fixed the bug that filename is percent encoded where it must be
|
||||
|
|
|
@ -104,7 +104,7 @@ size_t BtHandshakeMessage::getMessageLength() {
|
|||
|
||||
std::string BtHandshakeMessage::toString() const {
|
||||
return strconcat(NAME, " peerId=",
|
||||
util::urlencode(peerId, PEER_ID_LENGTH),
|
||||
util::percentEncode(peerId, PEER_ID_LENGTH),
|
||||
", reserved=",
|
||||
util::toHex(reserved, RESERVED_LENGTH));
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ public:
|
|||
if(memcmp(BtHandshakeMessage::BT_PSTR, message->getPstr(), 19) != 0) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("invalid handshake pstr=%s",
|
||||
util::urlencode(message->getPstr(), 19).c_str()).str());
|
||||
util::percentEncode
|
||||
(message->getPstr(), 19).c_str()).str());
|
||||
}
|
||||
if(memcmp(infoHash, message->getInfoHash(), 20) != 0) {
|
||||
throw DL_ABORT_EX
|
||||
|
|
|
@ -232,9 +232,11 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
|
|||
// for now, just report error message arrived and throw exception.
|
||||
const BDE& e = getList(dict, DHTUnknownMessage::E);
|
||||
if(e.size() == 2) {
|
||||
if(_logger->info()) {
|
||||
_logger->info("Received Error DHT message. code=%s, msg=%s",
|
||||
util::itos(getInteger(e, 0).i()).c_str(),
|
||||
util::urlencode(getString(e, 1).s()).c_str());
|
||||
util::percentEncode(getString(e, 1).s()).c_str());
|
||||
}
|
||||
} else {
|
||||
if(_logger->debug()) {
|
||||
_logger->debug("e doesn't have 2 elements.");
|
||||
|
@ -244,7 +246,7 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
|
|||
} else if(y.s() != DHTResponseMessage::R) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("Malformed DHT message. y != r: y=%s",
|
||||
util::urlencode(y.s()).c_str()).str());
|
||||
util::percentEncode(y.s()).c_str()).str());
|
||||
}
|
||||
const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
|
||||
const BDE& id = getString(rDict, DHTMessage::ID);
|
||||
|
|
|
@ -144,10 +144,11 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
|||
std::string uri = announceList.getAnnounce();
|
||||
uri += uriHasQuery(uri) ? "&" : "?";
|
||||
uri += "info_hash=";
|
||||
uri += util::torrentUrlencode(bittorrent::getInfoHash(_downloadContext),
|
||||
uri += util::torrentPercentEncode(bittorrent::getInfoHash(_downloadContext),
|
||||
INFO_HASH_LENGTH);
|
||||
uri += "&peer_id=";
|
||||
uri += util::torrentUrlencode(bittorrent::getStaticPeerId(), PEER_ID_LENGTH);
|
||||
uri += util::torrentPercentEncode(bittorrent::getStaticPeerId(),
|
||||
PEER_ID_LENGTH);
|
||||
uri += "&uploaded=";
|
||||
uri += util::uitos(stat.getSessionUploadLength());
|
||||
uri += "&downloaded=";
|
||||
|
@ -158,7 +159,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
|||
uri += "&key=";
|
||||
// Use last 8 bytes of peer ID as a key
|
||||
size_t keyLen = 8;
|
||||
uri += util::torrentUrlencode
|
||||
uri += util::torrentPercentEncode
|
||||
(bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen, keyLen);
|
||||
uri += "&numwant=";
|
||||
uri += util::uitos(numWant);
|
||||
|
@ -173,7 +174,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
|||
uri += event;
|
||||
}
|
||||
if(!trackerId.empty()) {
|
||||
uri += "&trackerid="+util::torrentUrlencode(trackerId);
|
||||
uri += "&trackerid="+util::torrentPercentEncode(trackerId);
|
||||
}
|
||||
if(option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
|
||||
uri += "&requirecrypto=1";
|
||||
|
|
|
@ -83,7 +83,7 @@ std::string HandshakeExtensionMessage::toString() const
|
|||
{
|
||||
std::string s = getExtensionName();
|
||||
if(!_clientVersion.empty()) {
|
||||
strappend(s, " client=", util::urlencode(_clientVersion));
|
||||
strappend(s, " client=", util::percentEncode(_clientVersion));
|
||||
}
|
||||
if(_tcpPort > 0) {
|
||||
strappend(s, ", tcpPort=", util::uitos(_tcpPort));
|
||||
|
@ -166,7 +166,7 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length)
|
|||
if(LogFactory::getInstance()->debug()) {
|
||||
LogFactory::getInstance()->debug
|
||||
("Creating HandshakeExtensionMessage from %s",
|
||||
util::urlencode(data, length).c_str());
|
||||
util::percentEncode(data, length).c_str());
|
||||
}
|
||||
const BDE dict = bencode::decode(data+1, length-1);
|
||||
if(!dict.isDict()) {
|
||||
|
|
|
@ -140,7 +140,7 @@ std::string HttpRequest::createRequest()
|
|||
// Insert user into URI, like ftp://USER@host/
|
||||
std::string uri = getCurrentURI();
|
||||
assert(uri.size() >= 6);
|
||||
uri.insert(6, util::urlencode(_authConfig->getUser())+"@");
|
||||
uri.insert(6, util::percentEncode(_authConfig->getUser())+"@");
|
||||
requestLine += uri;
|
||||
} else {
|
||||
requestLine += getCurrentURI();
|
||||
|
|
|
@ -474,7 +474,7 @@ static void gatherPeer(BDE& peers, const SharedHandle<PeerStorage>& ps)
|
|||
for(std::vector<SharedHandle<Peer> >::const_iterator i =
|
||||
activePeers.begin(), eoi = activePeers.end(); i != eoi; ++i) {
|
||||
BDE peerEntry = BDE::dict();
|
||||
peerEntry[KEY_PEER_ID] = util::torrentUrlencode((*i)->getPeerId(),
|
||||
peerEntry[KEY_PEER_ID] = util::torrentPercentEncode((*i)->getPeerId(),
|
||||
PEER_ID_LENGTH);
|
||||
peerEntry[KEY_IP] = (*i)->ipaddr;
|
||||
peerEntry[KEY_PORT] = util::uitos((*i)->port);
|
||||
|
|
|
@ -940,7 +940,7 @@ std::string torrent2Magnet(const BDE& attrs)
|
|||
}
|
||||
if(attrs.containsKey(NAME)) {
|
||||
uri += "&dn=";
|
||||
uri += util::urlencode(attrs[NAME].s());
|
||||
uri += util::percentEncode(attrs[NAME].s());
|
||||
}
|
||||
if(attrs.containsKey(ANNOUNCE_LIST)) {
|
||||
const BDE& tiers = attrs[ANNOUNCE_LIST];
|
||||
|
@ -949,7 +949,7 @@ std::string torrent2Magnet(const BDE& attrs)
|
|||
for(BDE::List::const_iterator uriiter = (*tieriter).listBegin(),
|
||||
eoi2 = (*tieriter).listEnd(); uriiter != eoi2; ++uriiter) {
|
||||
uri += "&tr=";
|
||||
uri += util::urlencode((*uriiter).s());
|
||||
uri += util::percentEncode((*uriiter).s());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/util.cc
12
src/util.cc
|
@ -290,7 +290,7 @@ bool inRFC2616HttpToken(const char c)
|
|||
&chars[arrayLength(chars)];
|
||||
}
|
||||
|
||||
std::string urlencode(const unsigned char* target, size_t len) {
|
||||
std::string percentEncode(const unsigned char* target, size_t len) {
|
||||
std::string dest;
|
||||
for(size_t i = 0; i < len; ++i) {
|
||||
if(!inRFC3986UnreservedChars(target[i])) {
|
||||
|
@ -302,13 +302,13 @@ std::string urlencode(const unsigned char* target, size_t len) {
|
|||
return dest;
|
||||
}
|
||||
|
||||
std::string urlencode(const std::string& target)
|
||||
std::string percentEncode(const std::string& target)
|
||||
{
|
||||
return urlencode(reinterpret_cast<const unsigned char*>(target.c_str()),
|
||||
return percentEncode(reinterpret_cast<const unsigned char*>(target.c_str()),
|
||||
target.size());
|
||||
}
|
||||
|
||||
std::string torrentUrlencode(const unsigned char* target, size_t len) {
|
||||
std::string torrentPercentEncode(const unsigned char* target, size_t len) {
|
||||
std::string dest;
|
||||
for(size_t i = 0; i < len; ++i) {
|
||||
if(isAlpha(target[i]) || isDigit(target[i])) {
|
||||
|
@ -320,9 +320,9 @@ std::string torrentUrlencode(const unsigned char* target, size_t len) {
|
|||
return dest;
|
||||
}
|
||||
|
||||
std::string torrentUrlencode(const std::string& target)
|
||||
std::string torrentPercentEncode(const std::string& target)
|
||||
{
|
||||
return torrentUrlencode
|
||||
return torrentPercentEncode
|
||||
(reinterpret_cast<const unsigned char*>(target.c_str()), target.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -137,9 +137,9 @@ bool endsWith(const std::string& target, const std::string& part);
|
|||
|
||||
std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr);
|
||||
|
||||
std::string urlencode(const unsigned char* target, size_t len);
|
||||
std::string percentEncode(const unsigned char* target, size_t len);
|
||||
|
||||
std::string urlencode(const std::string& target);
|
||||
std::string percentEncode(const std::string& target);
|
||||
|
||||
bool inRFC3986ReservedChars(const char c);
|
||||
|
||||
|
@ -147,9 +147,9 @@ bool inRFC3986UnreservedChars(const char c);
|
|||
|
||||
std::string urldecode(const std::string& target);
|
||||
|
||||
std::string torrentUrlencode(const unsigned char* target, size_t len);
|
||||
std::string torrentPercentEncode(const unsigned char* target, size_t len);
|
||||
|
||||
std::string torrentUrlencode(const std::string& target);
|
||||
std::string torrentPercentEncode(const std::string& target);
|
||||
|
||||
std::string toHex(const unsigned char* src, size_t len);
|
||||
|
||||
|
|
|
@ -70,8 +70,8 @@ void DHTAnnouncePeerMessageTest::testGetBencodedMessage()
|
|||
aDict["token"] = token;
|
||||
dict["a"] = aDict;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(util::urlencode(bencode::encode(dict)),
|
||||
util::urlencode(msgbody));
|
||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode::encode(dict)),
|
||||
util::percentEncode(msgbody));
|
||||
}
|
||||
|
||||
void DHTAnnouncePeerMessageTest::testDoReceivedAction()
|
||||
|
|
|
@ -89,8 +89,8 @@ void DHTGetPeersMessageTest::testGetBencodedMessage()
|
|||
aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
|
||||
dict["a"] = aDict;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(util::urlencode(bencode::encode(dict)),
|
||||
util::urlencode(msgbody));
|
||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode::encode(dict)),
|
||||
util::percentEncode(msgbody));
|
||||
}
|
||||
|
||||
void DHTGetPeersMessageTest::testDoReceivedAction()
|
||||
|
|
|
@ -70,8 +70,8 @@ void DHTGetPeersReplyMessageTest::testGetBencodedMessage()
|
|||
|
||||
rDict["nodes"] = compactNodeInfo;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(util::urlencode(bencode::encode(dict)),
|
||||
util::urlencode(msgbody));
|
||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode::encode(dict)),
|
||||
util::percentEncode(msgbody));
|
||||
}
|
||||
rDict.removeKey("nodes");
|
||||
{
|
||||
|
@ -90,8 +90,8 @@ void DHTGetPeersReplyMessageTest::testGetBencodedMessage()
|
|||
msg.setValues(peers);
|
||||
std::string msgbody = msg.getBencodedMessage();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(util::urlencode(bencode::encode(dict)),
|
||||
util::urlencode(msgbody));
|
||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode::encode(dict)),
|
||||
util::percentEncode(msgbody));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,8 +96,8 @@ void UTPexExtensionMessageTest::testGetBencodedData()
|
|||
std::string(&c3[0], &c3[6])+std::string(&c4[0], &c4[6])+
|
||||
"e";
|
||||
std::string bd = msg.getPayload();
|
||||
CPPUNIT_ASSERT_EQUAL(util::urlencode(expected),
|
||||
util::urlencode(bd));
|
||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(expected),
|
||||
util::percentEncode(bd));
|
||||
}
|
||||
|
||||
void UTPexExtensionMessageTest::testToString()
|
||||
|
|
|
@ -50,7 +50,7 @@ class UtilTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testItos);
|
||||
CPPUNIT_TEST(testUitos);
|
||||
CPPUNIT_TEST(testNtoh64);
|
||||
CPPUNIT_TEST(testUrlencode);
|
||||
CPPUNIT_TEST(testPercentEncode);
|
||||
CPPUNIT_TEST(testHtmlEscape);
|
||||
CPPUNIT_TEST(testJoinPath);
|
||||
CPPUNIT_TEST(testParseIndexPath);
|
||||
|
@ -101,7 +101,7 @@ public:
|
|||
void testItos();
|
||||
void testUitos();
|
||||
void testNtoh64();
|
||||
void testUrlencode();
|
||||
void testPercentEncode();
|
||||
void testHtmlEscape();
|
||||
void testJoinPath();
|
||||
void testParseIndexPath();
|
||||
|
@ -810,20 +810,20 @@ void UtilTest::testNtoh64()
|
|||
#endif // !WORDS_BIGENDIAN
|
||||
}
|
||||
|
||||
void UtilTest::testUrlencode()
|
||||
void UtilTest::testPercentEncode()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string("%3A%2F%3F%23%5B%5D%40%21%25%26%27%28%29%2A%2B%2C%3B%3D"),
|
||||
util::urlencode(":/?#[]@!%&'()*+,;="));
|
||||
util::percentEncode(":/?#[]@!%&'()*+,;="));
|
||||
|
||||
std::string unreserved =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789"
|
||||
"-._~";
|
||||
CPPUNIT_ASSERT_EQUAL(unreserved, util::urlencode(unreserved));
|
||||
CPPUNIT_ASSERT_EQUAL(unreserved, util::percentEncode(unreserved));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("1%5EA%20"), util::urlencode("1^A "));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("1%5EA%20"), util::percentEncode("1^A "));
|
||||
}
|
||||
|
||||
void UtilTest::testHtmlEscape()
|
||||
|
|
Loading…
Reference in New Issue