2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Append 'u' to hex mask.
	* src/Base64.cc
	* src/BitfieldMan.cc
	* src/BtHandshakeMessage.cc
	* src/BtHandshakeMessage.h
	* src/DHTBucket.cc
	* src/DHTRoutingTableDeserializer.cc
	* src/DHTRoutingTableSerializer.cc
	* src/DefaultBtProgressInfoFile.cc
	* src/MSEHandshake.h
	* src/MultiUrlRequestInfo.cc
	* src/Platform.cc
	* src/SpeedCalc.cc
	* src/UTPexExtensionMessage.cc
	* src/a2netcompat.h
	* src/base32.cc
	* src/bitfield.h
	* src/bittorrent_helper.cc
	* src/cookie_helper.cc
	* src/util.h
pull/1/head
Tatsuhiro Tsujikawa 2010-10-10 03:08:30 +00:00
parent 8e059b66fa
commit 983b6006fd
20 changed files with 75 additions and 56 deletions

View File

@ -1,3 +1,26 @@
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Append 'u' to hex mask.
* src/Base64.cc
* src/BitfieldMan.cc
* src/BtHandshakeMessage.cc
* src/BtHandshakeMessage.h
* src/DHTBucket.cc
* src/DHTRoutingTableDeserializer.cc
* src/DHTRoutingTableSerializer.cc
* src/DefaultBtProgressInfoFile.cc
* src/MSEHandshake.h
* src/MultiUrlRequestInfo.cc
* src/Platform.cc
* src/SpeedCalc.cc
* src/UTPexExtensionMessage.cc
* src/a2netcompat.h
* src/base32.cc
* src/bitfield.h
* src/bittorrent_helper.cc
* src/cookie_helper.cc
* src/util.h
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added util::lowercase() and util::uppercase(). Added util::lowercase() and util::uppercase().

View File

@ -86,21 +86,21 @@ void Base64::encode(unsigned char*& result, size_t& rlength,
n += *s++ << 8; n += *s++ << 8;
n += *s++; n += *s++;
*p++ = CHAR_TABLE[n >> 18]; *p++ = CHAR_TABLE[n >> 18];
*p++ = CHAR_TABLE[n >> 12&0x3f]; *p++ = CHAR_TABLE[n >> 12&0x3fu];
*p++ = CHAR_TABLE[n >> 6&0x3f]; *p++ = CHAR_TABLE[n >> 6&0x3fu];
*p++ = CHAR_TABLE[n&0x3f]; *p++ = CHAR_TABLE[n&0x3fu];
} }
if(r == 2) { if(r == 2) {
int n = *s++ << 16; int n = *s++ << 16;
n += *s++ << 8; n += *s++ << 8;
*p++ = CHAR_TABLE[n >> 18]; *p++ = CHAR_TABLE[n >> 18];
*p++ = CHAR_TABLE[n >> 12&0x3f]; *p++ = CHAR_TABLE[n >> 12&0x3fu];
*p++ = CHAR_TABLE[n >> 6&0x3f]; *p++ = CHAR_TABLE[n >> 6&0x3fu];
*p++ = '='; *p++ = '=';
} else if(r == 1) { } else if(r == 1) {
int n = *s++ << 16; int n = *s++ << 16;
*p++ = CHAR_TABLE[n >> 18]; *p++ = CHAR_TABLE[n >> 18];
*p++ = CHAR_TABLE[n >> 12&0x3f]; *p++ = CHAR_TABLE[n >> 12&0x3fu];
*p++ = '='; *p++ = '=';
*p++ = '='; *p++ = '=';
} }
@ -164,8 +164,8 @@ void Base64::decode(unsigned char*& result, size_t& rlength,
n += INDEX_TABLE[*s++] << 6; n += INDEX_TABLE[*s++] << 6;
n += INDEX_TABLE[*s++]; n += INDEX_TABLE[*s++];
*p++ = n >> 16; *p++ = n >> 16;
*p++ = n >> 8&0xff; *p++ = n >> 8&0xffu;
*p++ = n&0xff; *p++ = n&0xffu;
} }
if(r == 2) { if(r == 2) {
int n = INDEX_TABLE[*s++] << 18; int n = INDEX_TABLE[*s++] << 18;
@ -176,7 +176,7 @@ void Base64::decode(unsigned char*& result, size_t& rlength,
n += INDEX_TABLE[*s++] << 12; n += INDEX_TABLE[*s++] << 12;
n += INDEX_TABLE[*s++] << 6; n += INDEX_TABLE[*s++] << 6;
*p++ = n >> 16; *p++ = n >> 16;
*p++ = n >> 8&0xff; *p++ = n >> 8&0xffu;
} }
delete [] nsrc; delete [] nsrc;
} }

View File

@ -154,7 +154,7 @@ bool BitfieldMan::hasMissingPiece
if(filterEnabled_) { if(filterEnabled_) {
temp &= filterBitfield_[i]; temp &= filterBitfield_[i];
} }
if(temp&0xff) { if(temp&0xffu) {
retval = true; retval = true;
break; break;
} }
@ -445,7 +445,7 @@ static bool testAllBitSet
return true; return true;
} }
for(size_t i = 0; i < length-1; ++i) { for(size_t i = 0; i < length-1; ++i) {
if(bitfield[i] != 0xff) { if(bitfield[i] != 0xffu) {
return false; return false;
} }
} }

View File

@ -70,9 +70,9 @@ void BtHandshakeMessage::init() {
memcpy(pstr_, BT_PSTR, PSTR_LENGTH); memcpy(pstr_, BT_PSTR, PSTR_LENGTH);
memset(reserved_, 0, RESERVED_LENGTH); memset(reserved_, 0, RESERVED_LENGTH);
// fast extension // fast extension
reserved_[7] |= 0x04; reserved_[7] |= 0x04u;
// extended messaging // extended messaging
reserved_[5] |= 0x10; reserved_[5] |= 0x10u;
} }
SharedHandle<BtHandshakeMessage> SharedHandle<BtHandshakeMessage>
@ -110,17 +110,17 @@ std::string BtHandshakeMessage::toString() const {
} }
bool BtHandshakeMessage::isFastExtensionSupported() const { bool BtHandshakeMessage::isFastExtensionSupported() const {
return reserved_[7]&0x04; return reserved_[7]&0x04u;
} }
bool BtHandshakeMessage::isExtendedMessagingEnabled() const bool BtHandshakeMessage::isExtendedMessagingEnabled() const
{ {
return reserved_[5]&0x10; return reserved_[5]&0x10u;
} }
bool BtHandshakeMessage::isDHTEnabled() const bool BtHandshakeMessage::isDHTEnabled() const
{ {
return reserved_[7]&0x01; return reserved_[7]&0x01u;
} }
void BtHandshakeMessage::setInfoHash(const unsigned char* infoHash) void BtHandshakeMessage::setInfoHash(const unsigned char* infoHash)

View File

@ -91,9 +91,9 @@ public:
void setDHTEnabled(bool enabled) void setDHTEnabled(bool enabled)
{ {
if(enabled) { if(enabled) {
reserved_[7] |= 0x01; reserved_[7] |= 0x01u;
} else { } else {
reserved_[7] &= ~0x01; reserved_[7] &= ~0x01u;
} }
} }

View File

@ -68,7 +68,7 @@ DHTBucket::DHTBucket(const SharedHandle<DHTNode>& localNode):
lastUpdated_(global::wallclock), lastUpdated_(global::wallclock),
logger_(LogFactory::getInstance()) logger_(LogFactory::getInstance())
{ {
memset(max_, 0xff, DHT_ID_LENGTH); memset(max_, 0xffu, DHT_ID_LENGTH);
memset(min_, 0, DHT_ID_LENGTH); memset(min_, 0, DHT_ID_LENGTH);
} }

View File

@ -81,24 +81,24 @@ void DHTRoutingTableDeserializer::deserialize(std::istream& in)
char header[8]; char header[8];
memset(header, 0, sizeof(header)); memset(header, 0, sizeof(header));
// magic // magic
header[0] = 0xa1; header[0] = 0xa1u;
header[1] = 0xa2; header[1] = 0xa2u;
// format ID // format ID
header[2] = 0x02; header[2] = 0x02u;
// version // version
header[6] = 0; header[6] = 0;
header[7] = 0x03; header[7] = 0x03u;
char headerCompat[8]; char headerCompat[8];
memset(headerCompat, 0, sizeof(headerCompat)); memset(headerCompat, 0, sizeof(headerCompat));
// magic // magic
headerCompat[0] = 0xa1; headerCompat[0] = 0xa1u;
headerCompat[1] = 0xa2; headerCompat[1] = 0xa2u;
// format ID // format ID
headerCompat[2] = 0x02; headerCompat[2] = 0x02u;
// version // version
headerCompat[6] = 0; headerCompat[6] = 0;
headerCompat[7] = 0x02; headerCompat[7] = 0x02u;
char zero[18]; char zero[18];
memset(zero, 0, sizeof(zero)); memset(zero, 0, sizeof(zero));

View File

@ -72,13 +72,13 @@ void DHTRoutingTableSerializer::serialize(std::ostream& o)
char header[8]; char header[8];
memset(header, 0, sizeof(header)); memset(header, 0, sizeof(header));
// magic // magic
header[0] = 0xa1; header[0] = 0xa1u;
header[1] = 0xa2; header[1] = 0xa2u;
// format ID // format ID
header[2] = 0x02; header[2] = 0x02u;
// version // version
header[6] = 0; header[6] = 0;
header[7] = 0x03; header[7] = 0x03u;
char zero[18]; char zero[18];
memset(zero, 0, sizeof(zero)); memset(zero, 0, sizeof(zero));

View File

@ -120,7 +120,7 @@ void DefaultBtProgressInfoFile::save()
// file version: 16 bits // file version: 16 bits
// values: '1' // values: '1'
char version[] = { 0x00, 0x01 }; char version[] = { 0x00u, 0x01u };
o.write(version, sizeof(version)); o.write(version, sizeof(version));
// extension: 32 bits // extension: 32 bits
// If this is BitTorrent download, then 0x00000001 // If this is BitTorrent download, then 0x00000001

View File

@ -64,8 +64,8 @@ public:
enum CRYPTO_TYPE { enum CRYPTO_TYPE {
CRYPTO_NONE = 0, CRYPTO_NONE = 0,
CRYPTO_PLAIN_TEXT = 0x01, CRYPTO_PLAIN_TEXT = 0x01u,
CRYPTO_ARC4 = 0x02 CRYPTO_ARC4 = 0x02u
}; };
private: private:

View File

@ -67,10 +67,6 @@
namespace aria2 { namespace aria2 {
#ifndef SA_RESETHAND
# define SA_RESETHAND 0x80000000
#endif // SA_RESETHAND
namespace global { namespace global {
extern volatile sig_atomic_t globalHaltRequested; extern volatile sig_atomic_t globalHaltRequested;

View File

@ -44,7 +44,7 @@
#ifdef HAVE_WINSOCK2_H #ifdef HAVE_WINSOCK2_H
#ifndef _WIN32_WINNT #ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x501 # define _WIN32_WINNT 0x501u
#endif // _WIN32_WINNT #endif // _WIN32_WINNT
#include <winsock2.h> #include <winsock2.h>
#undef ERROR #undef ERROR

View File

@ -97,7 +97,7 @@ bool SpeedCalc::isIntervalOver(int64_t milliElapsed) const
void SpeedCalc::changeSw() { void SpeedCalc::changeSw() {
lengthArray_[sw_] = 0; lengthArray_[sw_] = 0;
cpArray_[sw_] = global::wallclock; cpArray_[sw_] = global::wallclock;
sw_ ^= 0x01; sw_ ^= 0x01u;
nextInterval_ = nextInterval_ =
cpArray_[sw_].difference(global::wallclock)+CHANGE_INTERVAL_SEC; cpArray_[sw_].difference(global::wallclock)+CHANGE_INTERVAL_SEC;
} }

View File

@ -100,10 +100,10 @@ UTPexExtensionMessage::createCompactPeerListAndFlag
(compact, (*itr)->getIPAddress(), (*itr)->getPort()); (compact, (*itr)->getIPAddress(), (*itr)->getPort());
if(compactlen == COMPACT_LEN_IPV4) { if(compactlen == COMPACT_LEN_IPV4) {
addrstring.append(&compact[0], &compact[compactlen]); addrstring.append(&compact[0], &compact[compactlen]);
flagstring += (*itr)->isSeeder() ? 0x02 : 0x00; flagstring += (*itr)->isSeeder() ? 0x02u : 0x00u;
} else if(compactlen == COMPACT_LEN_IPV6) { } else if(compactlen == COMPACT_LEN_IPV6) {
addrstring6.append(&compact[0], &compact[compactlen]); addrstring6.append(&compact[0], &compact[compactlen]);
flagstring6 += (*itr)->isSeeder() ? 0x02 : 0x00; flagstring6 += (*itr)->isSeeder() ? 0x02u : 0x00u;
} }
} }
return std::make_pair(std::make_pair(addrstring, flagstring), return std::make_pair(std::make_pair(addrstring, flagstring),

View File

@ -38,7 +38,7 @@
#ifdef __MINGW32__ #ifdef __MINGW32__
# ifndef WINVER # ifndef WINVER
# define WINVER 0x501 # define WINVER 0x501u
# endif // !WINVER # endif // !WINVER
# ifdef HAVE_WINSOCK2_H # ifdef HAVE_WINSOCK2_H
# ifndef FD_SETSIZE # ifndef FD_SETSIZE

View File

@ -53,12 +53,12 @@ std::string encode(const std::string& src)
uint64_t buf = 0; uint64_t buf = 0;
for(size_t i = 0; i < src.size(); ++i) { for(size_t i = 0; i < src.size(); ++i) {
buf <<= 8; buf <<= 8;
buf += src[i]&0xff; buf += src[i]&0xffu;
++count; ++count;
if(count == 5) { if(count == 5) {
char temp[8]; char temp[8];
for(size_t j = 0; j < 8; ++j) { for(size_t j = 0; j < 8; ++j) {
temp[7-j] = B32TABLE[buf&0x1f]; temp[7-j] = B32TABLE[buf&0x1fu];
buf >>= 5; buf >>= 5;
} }
ret += std::string(&temp[0], &temp[8]); ret += std::string(&temp[0], &temp[8]);
@ -82,7 +82,7 @@ std::string encode(const std::string& src)
} }
char temp[7]; char temp[7];
for(size_t j = 0; j < r; ++j) { for(size_t j = 0; j < r; ++j) {
temp[r-1-j] = B32TABLE[buf&0x1f]; temp[r-1-j] = B32TABLE[buf&0x1fu];
buf >>= 5; buf >>= 5;
} }
ret += std::string(&temp[0], &temp[r]); ret += std::string(&temp[0], &temp[r]);

View File

@ -48,7 +48,7 @@ namespace aria2 {
namespace bitfield { namespace bitfield {
// Returns the bit mask for the last byte. For example, nbits = 9, // Returns the bit mask for the last byte. For example, nbits = 9,
// then 0x80 is returned. nbits = 12, then 0xf0 is returned. // then 0x80u is returned. nbits = 12, then 0xf0u is returned.
inline unsigned char lastByteMask(size_t nbits) inline unsigned char lastByteMask(size_t nbits)
{ {
if(nbits == 0) { if(nbits == 0) {
@ -56,7 +56,7 @@ inline unsigned char lastByteMask(size_t nbits)
} else { } else {
int s = nbits%8; int s = nbits%8;
if(s == 0) { if(s == 0) {
return 0xff; return 0xffu;
} else { } else {
return -256 >> s; return -256 >> s;
} }

View File

@ -637,11 +637,11 @@ void computeFastSet
} }
unsigned char tx[24]; unsigned char tx[24];
memcpy(tx, compact, 4); memcpy(tx, compact, 4);
if((tx[0] & 0x80) == 0 || (tx[0] & 0x40) == 0) { if((tx[0] & 0x80u) == 0 || (tx[0] & 0x40u) == 0) {
tx[2] = 0x00; tx[2] = 0x00u;
tx[3] = 0x00; tx[3] = 0x00u;
} else { } else {
tx[3] = 0x00; tx[3] = 0x00u;
} }
memcpy(tx+4, infoHash, 20); memcpy(tx+4, infoHash, 20);
unsigned char x[20]; unsigned char x[20];

View File

@ -49,8 +49,8 @@ namespace cookie {
namespace { namespace {
bool isDelimiter(unsigned char c) bool isDelimiter(unsigned char c)
{ {
return c == 0x09U || in(c, 0x20U, 0x2fU) || in(c, 0x3bU, 0x40U) || return c == 0x09u || in(c, 0x20u, 0x2fu) || in(c, 0x3bu, 0x40u) ||
in(c, 0x5bU, 0x60U) || in(c, 0x7bU, 0x7eU); in(c, 0x5bu, 0x60u) || in(c, 0x7bu, 0x7eu);
} }
} // namespace } // namespace
@ -58,7 +58,7 @@ namespace {
std::string::const_iterator getNextDigit std::string::const_iterator getNextDigit
(std::string::const_iterator first, std::string::const_iterator last) (std::string::const_iterator first, std::string::const_iterator last)
{ {
for(; first != last && in(static_cast<unsigned char>(*first), 0x30U, 0x39U); for(; first != last && in(static_cast<unsigned char>(*first), 0x30u, 0x39u);
++first); ++first);
return first; return first;
} }

View File

@ -78,7 +78,7 @@ inline uint64_t ntoh64(uint64_t x) { return x; }
inline uint64_t hton64(uint64_t x) { return x; } inline uint64_t hton64(uint64_t x) { return x; }
#else // !WORDS_BIGENDIAN #else // !WORDS_BIGENDIAN
inline uint64_t byteswap64(uint64_t x) { inline uint64_t byteswap64(uint64_t x) {
uint64_t v1 = ntohl(x & 0x00000000ffffffff); uint64_t v1 = ntohl(x & 0x00000000ffffffffllu);
uint64_t v2 = ntohl(x >> 32); uint64_t v2 = ntohl(x >> 32);
return (v1 << 32)|v2; return (v1 << 32)|v2;
} }