Use PRId64 for int64_t format specifier

This commit is contained in:
Tatsuhiro Tsujikawa 2012-06-25 22:43:33 +09:00
parent 3620d271af
commit 4b03634f36
44 changed files with 206 additions and 213 deletions

View file

@ -121,7 +121,7 @@ AbstractCommand::~AbstractCommand() {
void AbstractCommand::useFasterRequest void AbstractCommand::useFasterRequest
(const SharedHandle<Request>& fasterRequest) (const SharedHandle<Request>& fasterRequest)
{ {
A2_LOG_INFO(fmt("CUID#%lld - Use faster Request hostname=%s, port=%u", A2_LOG_INFO(fmt("CUID#%" PRId64 " - Use faster Request hostname=%s, port=%u",
getCuid(), getCuid(),
fasterRequest->getHost().c_str(), fasterRequest->getHost().c_str(),
fasterRequest->getPort())); fasterRequest->getPort()));
@ -135,7 +135,7 @@ void AbstractCommand::useFasterRequest
} }
bool AbstractCommand::execute() { bool AbstractCommand::execute() {
A2_LOG_DEBUG(fmt("CUID#%lld - socket: read:%d, write:%d, hup:%d, err:%d", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - socket: read:%d, write:%d, hup:%d, err:%d",
getCuid(), getCuid(),
readEventEnabled(), readEventEnabled(),
writeEventEnabled(), writeEventEnabled(),
@ -146,7 +146,7 @@ bool AbstractCommand::execute() {
return true; return true;
} }
if(req_ && req_->removalRequested()) { if(req_ && req_->removalRequested()) {
A2_LOG_DEBUG(fmt("CUID#%lld - Discard original URI=%s because it is" A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Discard original URI=%s because it is"
" requested.", " requested.",
getCuid(), req_->getUri().c_str())); getCuid(), req_->getUri().c_str()));
return prepareForRetry(0); return prepareForRetry(0);
@ -158,7 +158,7 @@ bool AbstractCommand::execute() {
// This command previously has assigned segments, but it is // This command previously has assigned segments, but it is
// canceled. So discard current request chain. Plus, if no // canceled. So discard current request chain. Plus, if no
// segment is available when http pipelining is used. // segment is available when http pipelining is used.
A2_LOG_DEBUG(fmt("CUID#%lld - It seems previously assigned segments" A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - It seems previously assigned segments"
" are canceled. Restart.", " are canceled. Restart.",
getCuid())); getCuid()));
// Request::isPipeliningEnabled() == true means aria2 // Request::isPipeliningEnabled() == true means aria2
@ -273,7 +273,7 @@ bool AbstractCommand::execute() {
// empty. // empty.
if(!req_->getConnectedAddr().empty()) { if(!req_->getConnectedAddr().empty()) {
// Purging IP address cache to renew IP address. // Purging IP address cache to renew IP address.
A2_LOG_DEBUG(fmt("CUID#%lld - Marking IP address %s as bad", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Marking IP address %s as bad",
getCuid(), getCuid(),
req_->getConnectedAddr().c_str())); req_->getConnectedAddr().c_str()));
e_->markBadIPAddress(req_->getConnectedHostname(), e_->markBadIPAddress(req_->getConnectedHostname(),
@ -282,7 +282,7 @@ bool AbstractCommand::execute() {
} }
if(e_->findCachedIPAddress if(e_->findCachedIPAddress
(req_->getConnectedHostname(), req_->getConnectedPort()).empty()) { (req_->getConnectedHostname(), req_->getConnectedPort()).empty()) {
A2_LOG_DEBUG(fmt("CUID#%lld - All IP addresses were marked bad." A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - All IP addresses were marked bad."
" Removing Entry.", " Removing Entry.",
getCuid())); getCuid()));
e_->removeCachedIPAddress e_->removeCachedIPAddress
@ -370,14 +370,14 @@ void AbstractCommand::tryReserved() {
// and there are no URI left. Because file length is unknown, we // and there are no URI left. Because file length is unknown, we
// can assume that there are no in-flight request object. // can assume that there are no in-flight request object.
if(entry->getLength() == 0 && entry->getRemainingUris().empty()) { if(entry->getLength() == 0 && entry->getRemainingUris().empty()) {
A2_LOG_DEBUG(fmt("CUID#%lld - Not trying next request." A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Not trying next request."
" No reserved/pooled request is remaining and" " No reserved/pooled request is remaining and"
" total length is still unknown.", " total length is still unknown.",
getCuid())); getCuid()));
return; return;
} }
} }
A2_LOG_DEBUG(fmt("CUID#%lld - Trying reserved/pooled request.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Trying reserved/pooled request.",
getCuid())); getCuid()));
std::vector<Command*> commands; std::vector<Command*> commands;
requestGroup_->createNextCommand(commands, e_, 1); requestGroup_->createNextCommand(commands, e_, 1);
@ -397,7 +397,7 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
req_->setMaxPipelinedRequest(1); req_->setMaxPipelinedRequest(1);
fileEntry_->poolRequest(req_); fileEntry_->poolRequest(req_);
A2_LOG_DEBUG(fmt("CUID#%lld - Pooling request URI=%s", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Pooling request URI=%s",
getCuid(), req_->getUri().c_str())); getCuid(), req_->getUri().c_str()));
if(getSegmentMan()) { if(getSegmentMan()) {
getSegmentMan()->recognizeSegmentFor(fileEntry_); getSegmentMan()->recognizeSegmentFor(fileEntry_);
@ -422,7 +422,7 @@ void AbstractCommand::onAbort() {
fileEntry_->removeIdenticalURI(req_->getUri()); fileEntry_->removeIdenticalURI(req_->getUri());
fileEntry_->removeRequest(req_); fileEntry_->removeRequest(req_);
} }
A2_LOG_DEBUG(fmt("CUID#%lld - Aborting download", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Aborting download",
getCuid())); getCuid()));
if(getPieceStorage()) { if(getPieceStorage()) {
getSegmentMan()->cancelSegment(getCuid()); getSegmentMan()->cancelSegment(getCuid());
@ -440,10 +440,10 @@ void AbstractCommand::onAbort() {
// Local file exists, but given servers(or at least contacted // Local file exists, but given servers(or at least contacted
// ones) doesn't support resume. Let's restart download from // ones) doesn't support resume. Let's restart download from
// scratch. // scratch.
A2_LOG_NOTICE(fmt(_("CUID#%lld - Failed to resume download." A2_LOG_NOTICE(fmt(_("CUID#%" PRId64 " - Failed to resume download."
" Download from scratch."), " Download from scratch."),
getCuid())); getCuid()));
A2_LOG_DEBUG(fmt("CUID#%lld - Gathering URIs that has CANNOT_RESUME" A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Gathering URIs that has CANNOT_RESUME"
" error", " error",
getCuid())); getCuid()));
// Set PREF_ALWAYS_RESUME to A2_V_TRUE to avoid repeating this // Set PREF_ALWAYS_RESUME to A2_V_TRUE to avoid repeating this
@ -459,7 +459,7 @@ void AbstractCommand::onAbort() {
uris.reserve(res.size()); uris.reserve(res.size());
std::transform(res.begin(), res.end(), std::back_inserter(uris), std::transform(res.begin(), res.end(), std::back_inserter(uris),
std::mem_fun_ref(&URIResult::getURI)); std::mem_fun_ref(&URIResult::getURI));
A2_LOG_DEBUG(fmt("CUID#%lld - %lu URIs found.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - %lu URIs found.",
getCuid(), getCuid(),
static_cast<unsigned long int>(uris.size()))); static_cast<unsigned long int>(uris.size())));
fileEntry_->addUris(uris.begin(), uris.end()); fileEntry_->addUris(uris.begin(), uris.end());
@ -675,9 +675,9 @@ SharedHandle<Request> AbstractCommand::createProxyRequest() const
if(!proxy.empty()) { if(!proxy.empty()) {
proxyRequest.reset(new Request()); proxyRequest.reset(new Request());
if(proxyRequest->setUri(proxy)) { if(proxyRequest->setUri(proxy)) {
A2_LOG_DEBUG(fmt("CUID#%lld - Using proxy", getCuid())); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Using proxy", getCuid()));
} else { } else {
A2_LOG_DEBUG(fmt("CUID#%lld - Failed to parse proxy string", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Failed to parse proxy string",
getCuid())); getCuid()));
proxyRequest.reset(); proxyRequest.reset();
} }

View file

@ -215,9 +215,9 @@ void AbstractDiskWriter::ensureMmapWrite(size_t len, off_t offset)
mapaddr_ = reinterpret_cast<unsigned char*> mapaddr_ = reinterpret_cast<unsigned char*>
(mmap(0, size(), PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0)); (mmap(0, size(), PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0));
if(mapaddr_) { if(mapaddr_) {
A2_LOG_DEBUG(fmt("mmap for file %s succeeded, length=%lld", A2_LOG_DEBUG(fmt("mmap for file %s succeeded, length=%" PRId64 "",
filename_.c_str(), filename_.c_str(),
static_cast<long long int>(filesize))); static_cast<uint64_t>(filesize)));
maplen_ = filesize; maplen_ = filesize;
} else { } else {
int errNum = errno; int errNum = errno;

View file

@ -75,19 +75,19 @@ bool AbstractHttpServerResponseCommand::execute()
httpServer_->sendResponse(); httpServer_->sendResponse();
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
A2_LOG_INFO_EX A2_LOG_INFO_EX
(fmt("CUID#%lld - Error occurred while transmitting response body.", (fmt("CUID#%" PRId64 " - Error occurred while transmitting response body.",
getCuid()), getCuid()),
e); e);
return true; return true;
} }
if(httpServer_->sendBufferIsEmpty()) { if(httpServer_->sendBufferIsEmpty()) {
A2_LOG_INFO(fmt("CUID#%lld - HttpServer: all response transmitted.", A2_LOG_INFO(fmt("CUID#%" PRId64 " - HttpServer: all response transmitted.",
getCuid())); getCuid()));
afterSend(httpServer_, e_); afterSend(httpServer_, e_);
return true; return true;
} else { } else {
if(timeoutTimer_.difference(global::wallclock()) >= 10) { if(timeoutTimer_.difference(global::wallclock()) >= 10) {
A2_LOG_INFO(fmt("CUID#%lld - HttpServer: Timeout while trasmitting" A2_LOG_INFO(fmt("CUID#%" PRId64 " - HttpServer: Timeout while trasmitting"
" response.", " response.",
getCuid())); getCuid()));
return true; return true;

View file

@ -155,11 +155,11 @@ bool BtDependency::resolve()
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
A2_LOG_INFO(fmt("BtDependency for GID#%lld failed. Go without Bt.", A2_LOG_INFO(fmt("BtDependency for GID#%" PRId64 " failed. Go without Bt.",
dependant_->getGID())); dependant_->getGID()));
return true; return true;
} }
A2_LOG_INFO(fmt("Dependency resolved for GID#%lld", A2_LOG_INFO(fmt("Dependency resolved for GID#%" PRId64 "",
dependant_->getGID())); dependant_->getGID()));
dependant_->setDownloadContext(context); dependant_->setDownloadContext(context);
return true; return true;
@ -167,7 +167,7 @@ bool BtDependency::resolve()
// dependee_'s download failed. // dependee_'s download failed.
// cut reference here // cut reference here
dependee_.reset(); dependee_.reset();
A2_LOG_INFO(fmt("BtDependency for GID#%lld failed. Go without Bt.", A2_LOG_INFO(fmt("BtDependency for GID#%" PRId64 " failed. Go without Bt.",
dependant_->getGID())); dependant_->getGID()));
return true; return true;
} else { } else {

View file

@ -109,7 +109,7 @@ void BtPieceMessage::doReceivedAction()
static_cast<unsigned long>(index_), static_cast<unsigned long>(index_),
begin_, begin_,
blockLength_, blockLength_,
static_cast<long long int>(offset), static_cast<int64_t>(offset),
static_cast<unsigned long>(slot.getBlockIndex()))); static_cast<unsigned long>(slot.getBlockIndex())));
if(piece->hasBlock(slot.getBlockIndex())) { if(piece->hasBlock(slot.getBlockIndex())) {
A2_LOG_DEBUG("Already have this block."); A2_LOG_DEBUG("Already have this block.");
@ -133,7 +133,7 @@ void BtPieceMessage::doReceivedAction()
} }
} }
} else { } else {
A2_LOG_DEBUG(fmt("CUID#%lld - RequestSlot not found, index=%lu, begin=%d", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - RequestSlot not found, index=%lu, begin=%d",
getCuid(), getCuid(),
static_cast<unsigned long>(index_), static_cast<unsigned long>(index_),
begin_)); begin_));

View file

@ -61,7 +61,7 @@ void BtStopDownloadCommand::preProcess()
enableExit(); enableExit();
} }
if(checkPoint_.difference(global::wallclock()) >= timeout_) { if(checkPoint_.difference(global::wallclock()) >= timeout_) {
A2_LOG_NOTICE(fmt(_("GID#%lld Stop downloading torrent due to" A2_LOG_NOTICE(fmt(_("GID#%" PRId64 " Stop downloading torrent due to"
" --bt-stop-timeout option."), " --bt-stop-timeout option."),
requestGroup_->getGID())); requestGroup_->getGID()));
requestGroup_->setForceHaltRequested(true); requestGroup_->setForceHaltRequested(true);

View file

@ -56,7 +56,7 @@ Command* CheckIntegrityDispatcherCommand::createCommand
(const SharedHandle<CheckIntegrityEntry>& entry) (const SharedHandle<CheckIntegrityEntry>& entry)
{ {
cuid_t newCUID = getDownloadEngine()->newCUID(); cuid_t newCUID = getDownloadEngine()->newCUID();
A2_LOG_INFO(fmt("CUID#%lld - Dispatching CheckIntegrityCommand CUID#%lld.", A2_LOG_INFO(fmt("CUID#%" PRId64 " - Dispatching CheckIntegrityCommand CUID#%" PRId64 ".",
getCuid(), newCUID)); getCuid(), newCUID));
return new CheckIntegrityCommand return new CheckIntegrityCommand
(newCUID, entry->getRequestGroup(), getDownloadEngine(), entry); (newCUID, entry->getRequestGroup(), getDownloadEngine(), entry);

View file

@ -39,7 +39,7 @@
namespace aria2 { namespace aria2 {
typedef long long int cuid_t; typedef int64_t cuid_t;
class Command { class Command {
public: public:

View file

@ -183,8 +183,7 @@ void DHTMessageFactoryImpl::validatePort(const Integer* port) const
{ {
if(!(0 < port->i() && port->i() < UINT16_MAX)) { if(!(0 < port->i() && port->i() < UINT16_MAX)) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt("Malformed DHT message. Invalid port=%lld", (fmt("Malformed DHT message. Invalid port=%" PRId64 "", port->i()));
static_cast<long long int>(port->i())));
} }
} }
@ -256,8 +255,8 @@ DHTMessageFactoryImpl::createResponseMessage
// for now, just report error message arrived and throw exception. // for now, just report error message arrived and throw exception.
const List* e = getList(dict, DHTUnknownMessage::E); const List* e = getList(dict, DHTUnknownMessage::E);
if(e->size() == 2) { if(e->size() == 2) {
A2_LOG_INFO(fmt("Received Error DHT message. code=%lld, msg=%s", A2_LOG_INFO(fmt("Received Error DHT message. code=%" PRId64 ", msg=%s",
static_cast<long long int>(getInteger(e, 0)->i()), getInteger(e, 0)->i(),
util::percentEncode(getString(e, 1)->s()).c_str())); util::percentEncode(getString(e, 1)->s()).c_str()));
} else { } else {
A2_LOG_DEBUG("e doesn't have 2 elements."); A2_LOG_DEBUG("e doesn't have 2 elements.");

View file

@ -87,7 +87,7 @@ DHTMessageTracker::messageArrived
targetNode->getPort()); targetNode->getPort());
int64_t rtt = entry->getElapsedMillis(); int64_t rtt = entry->getElapsedMillis();
A2_LOG_DEBUG(fmt("RTT is %lld", static_cast<long long int>(rtt))); A2_LOG_DEBUG(fmt("RTT is %" PRId64 "", rtt));
message->getRemoteNode()->updateRTT(rtt); message->getRemoteNode()->updateRTT(rtt);
SharedHandle<DHTMessageCallback> callback = entry->getCallback(); SharedHandle<DHTMessageCallback> callback = entry->getCallback();
if(!(*targetNode == *message->getRemoteNode())) { if(!(*targetNode == *message->getRemoteNode())) {

View file

@ -142,7 +142,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
numWant = 0; numWant = 0;
} }
TransferStat stat = peerStorage_->calculateStat(); TransferStat stat = peerStorage_->calculateStat();
off_t left = int64_t left =
pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength(); pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength();
// Use last 8 bytes of peer ID as a key // Use last 8 bytes of peer ID as a key
const size_t keyLen = 8; const size_t keyLen = 8;
@ -150,9 +150,9 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
uri += uriHasQuery(uri) ? "&" : "?"; uri += uriHasQuery(uri) ? "&" : "?";
uri += fmt("info_hash=%s&" uri += fmt("info_hash=%s&"
"peer_id=%s&" "peer_id=%s&"
"uploaded=%lld&" "uploaded=%" PRId64 "&"
"downloaded=%lld&" "downloaded=%" PRId64 "&"
"left=%lld&" "left=%" PRId64 "&"
"compact=1&" "compact=1&"
"key=%s&" "key=%s&"
"numwant=%d&" "numwant=%d&"
@ -162,9 +162,9 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
INFO_HASH_LENGTH).c_str(), INFO_HASH_LENGTH).c_str(),
util::torrentPercentEncode util::torrentPercentEncode
(bittorrent::getStaticPeerId(), PEER_ID_LENGTH).c_str(), (bittorrent::getStaticPeerId(), PEER_ID_LENGTH).c_str(),
static_cast<long long int>(stat.getSessionUploadLength()), stat.getSessionUploadLength(),
static_cast<long long int>(stat.getSessionDownloadLength()), stat.getSessionDownloadLength(),
static_cast<long long int>(left), left,
util::torrentPercentEncode util::torrentPercentEncode
(bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen, (bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen,
keyLen).c_str(), keyLen).c_str(),

View file

@ -117,7 +117,7 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(), if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(),
PEER_ID_LENGTH) == 0) { PEER_ID_LENGTH) == 0) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt("CUID#%lld - Drop connection from the same Peer ID", (fmt("CUID#%" PRId64 " - Drop connection from the same Peer ID",
cuid_)); cuid_));
} }
std::vector<SharedHandle<Peer> > activePeers; std::vector<SharedHandle<Peer> > activePeers;
@ -126,7 +126,7 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
eoi = activePeers.end(); i != eoi; ++i) { eoi = activePeers.end(); i != eoi; ++i) {
if(memcmp((*i)->getPeerId(), message->getPeerId(), PEER_ID_LENGTH) == 0) { if(memcmp((*i)->getPeerId(), message->getPeerId(), PEER_ID_LENGTH) == 0) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt("CUID#%lld - Same Peer ID has been already seen.", (fmt("CUID#%" PRId64 " - Same Peer ID has been already seen.",
cuid_)); cuid_));
} }
} }

View file

@ -276,9 +276,9 @@ void DefaultBtProgressInfoFile::load()
} }
if(totalLength != static_cast<uint64_t>(dctx_->getTotalLength())) { if(totalLength != static_cast<uint64_t>(dctx_->getTotalLength())) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt("total length mismatch. expected: %lld, actual: %lld", (fmt("total length mismatch. expected: %" PRId64 ", actual: %" PRId64 "",
static_cast<long long int>(dctx_->getTotalLength()), static_cast<int64_t>(dctx_->getTotalLength()),
static_cast<long long int>(totalLength))); static_cast<int64_t>(totalLength)));
} }
uint64_t uploadLength; uint64_t uploadLength;
READ_CHECK(fp, &uploadLength, sizeof(uploadLength)); READ_CHECK(fp, &uploadLength, sizeof(uploadLength));

View file

@ -361,7 +361,7 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
} else { } else {
A2_LOG_INFO(fmt(EX_INVALID_CHUNK_CHECKSUM, A2_LOG_INFO(fmt(EX_INVALID_CHUNK_CHECKSUM,
static_cast<unsigned long>(segment->getIndex()), static_cast<unsigned long>(segment->getIndex()),
static_cast<long long int>(segment->getPosition()), static_cast<int64_t>(segment->getPosition()),
util::toHex(expectedHash).c_str(), util::toHex(expectedHash).c_str(),
util::toHex(actualHash).c_str())); util::toHex(actualHash).c_str()));
segment->clear(); segment->clear();

View file

@ -71,7 +71,7 @@ bool FileAllocationCommand::executeInternal()
A2_LOG_DEBUG A2_LOG_DEBUG
(fmt(MSG_ALLOCATION_COMPLETED, (fmt(MSG_ALLOCATION_COMPLETED,
static_cast<long int>(timer_.difference(global::wallclock())), static_cast<long int>(timer_.difference(global::wallclock())),
static_cast<long long int>(getRequestGroup()->getTotalLength()))); static_cast<int64_t>(getRequestGroup()->getTotalLength())));
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry(); getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
std::vector<Command*>* commands = new std::vector<Command*>(); std::vector<Command*>* commands = new std::vector<Command*>();

View file

@ -254,9 +254,10 @@ bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
{ {
if(socketBuffer_.sendBufferIsEmpty()) { if(socketBuffer_.sendBufferIsEmpty()) {
std::string request = std::string request =
fmt("REST %lld\r\n", fmt("REST %" PRId64 "\r\n",
segment ? segment ?
static_cast<long long int>(segment->getPositionToWrite()) : 0LL); static_cast<int64_t>(segment->getPositionToWrite()) :
static_cast<int64_t>(0LL));
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
cuid_, request.c_str())); cuid_, request.c_str()));
socketBuffer_.pushStr(request); socketBuffer_.pushStr(request);
@ -392,7 +393,7 @@ int FtpConnection::receiveResponse()
# define LONGLONG_SCANF "%I64d" # define LONGLONG_SCANF "%I64d"
# define ULONGLONG_SCANF "%I64u" # define ULONGLONG_SCANF "%I64u"
#else #else
# define LONGLONG_PRINTF "%lld" # define LONGLONG_PRINTF "%" PRId64 ""
# define ULONGLONG_PRINTF "%llu" # define ULONGLONG_PRINTF "%llu"
# define LONGLONG_SCANF "%Ld" # define LONGLONG_SCANF "%Ld"
// Mac OSX uses "%llu" for 64bits integer. // Mac OSX uses "%llu" for 64bits integer.

View file

@ -92,18 +92,18 @@ bool FtpFinishDownloadCommand::execute()
getSocket(), options); getSocket(), options);
} }
} else { } else {
A2_LOG_INFO(fmt("CUID#%lld - Bad status for transfer complete.", A2_LOG_INFO(fmt("CUID#%" PRId64 " - Bad status for transfer complete.",
getCuid())); getCuid()));
} }
} else if(getCheckPoint().difference(global::wallclock()) >= getTimeout()) { } else if(getCheckPoint().difference(global::wallclock()) >= getTimeout()) {
A2_LOG_INFO(fmt("CUID#%lld - Timeout before receiving transfer complete.", A2_LOG_INFO(fmt("CUID#%" PRId64 " - Timeout before receiving transfer complete.",
getCuid())); getCuid()));
} else { } else {
getDownloadEngine()->addCommand(this); getDownloadEngine()->addCommand(this);
return false; return false;
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
A2_LOG_INFO_EX(fmt("CUID#%lld - Exception was thrown, but download was" A2_LOG_INFO_EX(fmt("CUID#%" PRId64 " - Exception was thrown, but download was"
" finished, so we can ignore the exception.", " finished, so we can ignore the exception.",
getCuid()), getCuid()),
e); e);

View file

@ -265,7 +265,7 @@ bool FtpNegotiationCommand::recvPwd()
error_code::FTP_PROTOCOL_ERROR); error_code::FTP_PROTOCOL_ERROR);
} }
ftp_->setBaseWorkingDir(pwd); ftp_->setBaseWorkingDir(pwd);
A2_LOG_INFO(fmt("CUID#%lld - base working directory is '%s'", A2_LOG_INFO(fmt("CUID#%" PRId64 " - base working directory is '%s'",
getCuid(), pwd.c_str())); getCuid(), pwd.c_str()));
sequence_ = SEQ_SEND_CWD_PREP; sequence_ = SEQ_SEND_CWD_PREP;
return true; return true;
@ -350,7 +350,7 @@ bool FtpNegotiationCommand::recvMdtm()
" a time value as in specified in RFC3659."); " a time value as in specified in RFC3659.");
} }
} else { } else {
A2_LOG_INFO(fmt("CUID#%lld - MDTM command failed.", A2_LOG_INFO(fmt("CUID#%" PRId64 " - MDTM command failed.",
getCuid())); getCuid()));
} }
sequence_ = SEQ_SEND_SIZE; sequence_ = SEQ_SEND_SIZE;
@ -502,9 +502,8 @@ bool FtpNegotiationCommand::recvSize() {
} }
if(status == 213) { if(status == 213) {
if(size > std::numeric_limits<off_t>::max()) { if(size > std::numeric_limits<off_t>::max()) {
throw DL_ABORT_EX2 throw DL_ABORT_EX2(fmt(EX_TOO_LARGE_FILE, size),
(fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(size)), error_code::FTP_PROTOCOL_ERROR);
error_code::FTP_PROTOCOL_ERROR);
} }
if(!getPieceStorage()) { if(!getPieceStorage()) {
@ -516,7 +515,7 @@ bool FtpNegotiationCommand::recvSize() {
} }
} else { } else {
A2_LOG_INFO(fmt("CUID#%lld - The remote FTP Server doesn't recognize SIZE" A2_LOG_INFO(fmt("CUID#%" PRId64 " - The remote FTP Server doesn't recognize SIZE"
" command. Continue.", getCuid())); " command. Continue.", getCuid()));
// Even if one of the other servers waiting in the queue supports SIZE // Even if one of the other servers waiting in the queue supports SIZE
// command, resuming and segmented downloading are disabled when the first // command, resuming and segmented downloading are disabled when the first

View file

@ -142,7 +142,7 @@ RangeHandle HttpHeader::getRange() const
throw DL_ABORT_EX("Content-Length must be positive"); throw DL_ABORT_EX("Content-Length must be positive");
} else if(contentLength > std::numeric_limits<off_t>::max()) { } else if(contentLength > std::numeric_limits<off_t>::max()) {
throw DOWNLOAD_FAILURE_EXCEPTION throw DOWNLOAD_FAILURE_EXCEPTION
(fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(contentLength))); (fmt(EX_TOO_LARGE_FILE, contentLength));
} else if(contentLength == 0) { } else if(contentLength == 0) {
return SharedHandle<Range>(new Range()); return SharedHandle<Range>(new Range());
} else { } else {
@ -187,16 +187,13 @@ RangeHandle HttpHeader::getRange() const
throw DL_ABORT_EX("byte-range-spec must be positive"); throw DL_ABORT_EX("byte-range-spec must be positive");
} }
if(startByte > std::numeric_limits<off_t>::max()) { if(startByte > std::numeric_limits<off_t>::max()) {
throw DOWNLOAD_FAILURE_EXCEPTION throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, startByte));
(fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(startByte)));
} }
if(endByte > std::numeric_limits<off_t>::max()) { if(endByte > std::numeric_limits<off_t>::max()) {
throw DOWNLOAD_FAILURE_EXCEPTION throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, endByte));
(fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(endByte)));
} }
if(entityLength > std::numeric_limits<off_t>::max()) { if(entityLength > std::numeric_limits<off_t>::max()) {
throw DOWNLOAD_FAILURE_EXCEPTION throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, entityLength));
(fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(entityLength)));
} }
return SharedHandle<Range>(new Range(startByte, endByte, entityLength)); return SharedHandle<Range>(new Range(startByte, endByte, entityLength));
} }

View file

@ -193,8 +193,8 @@ std::string HttpRequest::createRequest()
} }
if(segment_ && segment_->getLength() > 0 && if(segment_ && segment_->getLength() > 0 &&
(request_->isPipeliningEnabled() || getStartByte() > 0)) { (request_->isPipeliningEnabled() || getStartByte() > 0)) {
std::string rangeHeader(fmt("bytes=%lld-", std::string rangeHeader(fmt("bytes=%" PRId64 "-",
static_cast<long long int>(getStartByte()))); static_cast<int64_t>(getStartByte())));
if(request_->isPipeliningEnabled()) { if(request_->isPipeliningEnabled()) {
rangeHeader += util::itos(getEndByte()); rangeHeader += util::itos(getEndByte());
} else if(getProtocol() != Request::PROTO_FTP && endOffsetOverride_ > 0) { } else if(getProtocol() != Request::PROTO_FTP && endOffsetOverride_ > 0) {

View file

@ -100,12 +100,12 @@ void HttpResponse::validateResponse() const
if(!httpRequest_->isRangeSatisfied(responseRange)) { if(!httpRequest_->isRangeSatisfied(responseRange)) {
throw DL_ABORT_EX2 throw DL_ABORT_EX2
(fmt(EX_INVALID_RANGE_HEADER, (fmt(EX_INVALID_RANGE_HEADER,
static_cast<long long int>(httpRequest_->getStartByte()), static_cast<int64_t>(httpRequest_->getStartByte()),
static_cast<long long int>(httpRequest_->getEndByte()), static_cast<int64_t>(httpRequest_->getEndByte()),
static_cast<long long int>(httpRequest_->getEntityLength()), static_cast<int64_t>(httpRequest_->getEntityLength()),
static_cast<long long int>(responseRange->getStartByte()), static_cast<int64_t>(responseRange->getStartByte()),
static_cast<long long int>(responseRange->getEndByte()), static_cast<int64_t>(responseRange->getEndByte()),
static_cast<long long int>(responseRange->getEntityLength())), static_cast<int64_t>(responseRange->getEntityLength())),
error_code::CANNOT_RESUME); error_code::CANNOT_RESUME);
} }
} }
@ -170,7 +170,7 @@ void HttpResponse::processRedirect()
httpRequest_->getRequest()->getCurrentUri().c_str())); httpRequest_->getRequest()->getCurrentUri().c_str()));
} else { } else {
throw DL_RETRY_EX throw DL_RETRY_EX
(fmt("CUID#%lld - Redirect to %s failed. It may not be a valid URI.", (fmt("CUID#%" PRId64 " - Redirect to %s failed. It may not be a valid URI.",
cuid_, cuid_,
httpRequest_->getRequest()->getCurrentUri().c_str())); httpRequest_->getRequest()->getCurrentUri().c_str()));
} }

View file

@ -195,7 +195,7 @@ bool HttpServerBodyCommand::execute()
req = rpc::xmlParseMemory(body.c_str(), body.size()); req = rpc::xmlParseMemory(body.c_str(), body.size());
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
A2_LOG_INFO_EX A2_LOG_INFO_EX
(fmt("CUID#%lld - Failed to parse XML-RPC request", (fmt("CUID#%" PRId64 " - Failed to parse XML-RPC request",
getCuid()), getCuid()),
e); e);
httpServer_->feedResponse(400); httpServer_->feedResponse(400);
@ -228,7 +228,7 @@ bool HttpServerBodyCommand::execute()
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
A2_LOG_INFO_EX A2_LOG_INFO_EX
(fmt("CUID#%lld - Failed to parse JSON-RPC request", (fmt("CUID#%" PRId64 " - Failed to parse JSON-RPC request",
getCuid()), getCuid()),
e); e);
rpc::RpcResponse res rpc::RpcResponse res
@ -283,7 +283,7 @@ bool HttpServerBodyCommand::execute()
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
A2_LOG_INFO_EX A2_LOG_INFO_EX
(fmt("CUID#%lld - Error occurred while reading HTTP request body", (fmt("CUID#%" PRId64 " - Error occurred while reading HTTP request body",
getCuid()), getCuid()),
e); e);
return true; return true;

View file

@ -216,10 +216,10 @@ bool HttpServerCommand::execute()
if(e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE) < if(e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE) <
httpServer_->getContentLength()) { httpServer_->getContentLength()) {
A2_LOG_INFO A2_LOG_INFO
(fmt("Request too long. ContentLength=%lld." (fmt("Request too long. ContentLength=%" PRId64 "."
" See --rpc-max-request-size option to loose" " See --rpc-max-request-size option to loose"
" this limitation.", " this limitation.",
static_cast<long long int>(httpServer_->getContentLength()))); static_cast<int64_t>(httpServer_->getContentLength())));
return true; return true;
} }
Command* command = new HttpServerBodyCommand(getCuid(), httpServer_, e_, Command* command = new HttpServerBodyCommand(getCuid(), httpServer_, e_,
@ -238,7 +238,7 @@ bool HttpServerCommand::execute()
} }
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
A2_LOG_INFO_EX(fmt("CUID#%lld - Error occurred while reading HTTP request", A2_LOG_INFO_EX(fmt("CUID#%" PRId64 " - Error occurred while reading HTTP request",
getCuid()), getCuid()),
e); e);
return true; return true;

View file

@ -60,7 +60,7 @@ void HttpServerResponseCommand::afterSend
DownloadEngine* e) DownloadEngine* e)
{ {
if(httpServer->supportsPersistentConnection()) { if(httpServer->supportsPersistentConnection()) {
A2_LOG_INFO(fmt("CUID#%lld - Persist connection.", A2_LOG_INFO(fmt("CUID#%" PRId64 " - Persist connection.",
getCuid())); getCuid()));
e->addCommand e->addCommand
(new HttpServerCommand(getCuid(), httpServer, e, (new HttpServerCommand(getCuid(), httpServer, e,

View file

@ -217,14 +217,14 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
tryNewPeer(); tryNewPeer();
return true; return true;
} else if(getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) { } else if(getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
A2_LOG_INFO(fmt("CUID#%lld - Establishing connection using legacy" A2_LOG_INFO(fmt("CUID#%" PRId64 " - Establishing connection using legacy"
" BitTorrent handshake is disabled by preference.", " BitTorrent handshake is disabled by preference.",
getCuid())); getCuid()));
tryNewPeer(); tryNewPeer();
return true; return true;
} else { } else {
// try legacy BitTorrent handshake // try legacy BitTorrent handshake
A2_LOG_INFO(fmt("CUID#%lld - Retry using legacy BitTorrent handshake.", A2_LOG_INFO(fmt("CUID#%" PRId64 " - Retry using legacy BitTorrent handshake.",
getCuid())); getCuid()));
PeerInitiateConnectionCommand* command = PeerInitiateConnectionCommand* command =
new PeerInitiateConnectionCommand(getCuid(), requestGroup_, getPeer(), new PeerInitiateConnectionCommand(getCuid(), requestGroup_, getPeer(),

View file

@ -78,7 +78,7 @@ void IteratableChunkChecksumValidator::validateChunk()
A2_LOG_INFO A2_LOG_INFO
(fmt(EX_INVALID_CHUNK_CHECKSUM, (fmt(EX_INVALID_CHUNK_CHECKSUM,
static_cast<unsigned long>(currentIndex_), static_cast<unsigned long>(currentIndex_),
static_cast<long long int>(getCurrentOffset()), static_cast<int64_t>(getCurrentOffset()),
util::toHex(dctx_->getPieceHashes()[currentIndex_]).c_str(), util::toHex(dctx_->getPieceHashes()[currentIndex_]).c_str(),
util::toHex(actualChecksum).c_str())); util::toHex(actualChecksum).c_str()));
bitfield_->unsetBit(currentIndex_); bitfield_->unsetBit(currentIndex_);

View file

@ -104,11 +104,11 @@ MSEHandshake::HANDSHAKE_TYPE MSEHandshake::identifyHandshakeType()
} }
if(rbuf_[0] == BtHandshakeMessage::PSTR_LENGTH && if(rbuf_[0] == BtHandshakeMessage::PSTR_LENGTH &&
memcmp(BtHandshakeMessage::BT_PSTR, rbuf_+1, 19) == 0) { memcmp(BtHandshakeMessage::BT_PSTR, rbuf_+1, 19) == 0) {
A2_LOG_DEBUG(fmt("CUID#%lld - This is legacy BitTorrent handshake.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - This is legacy BitTorrent handshake.",
cuid_)); cuid_));
return HANDSHAKE_LEGACY; return HANDSHAKE_LEGACY;
} else { } else {
A2_LOG_DEBUG(fmt("CUID#%lld - This may be encrypted BitTorrent handshake.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - This may be encrypted BitTorrent handshake.",
cuid_)); cuid_));
return HANDSHAKE_ENCRYPTED; return HANDSHAKE_ENCRYPTED;
} }
@ -120,13 +120,13 @@ void MSEHandshake::initEncryptionFacility(bool initiator)
dh_ = new DHKeyExchange(); dh_ = new DHKeyExchange();
dh_->init(PRIME, PRIME_BITS, GENERATOR, 160); dh_->init(PRIME, PRIME_BITS, GENERATOR, 160);
dh_->generatePublicKey(); dh_->generatePublicKey();
A2_LOG_DEBUG(fmt("CUID#%lld - DH initialized.", cuid_)); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - DH initialized.", cuid_));
initiator_ = initiator; initiator_ = initiator;
} }
void MSEHandshake::sendPublicKey() void MSEHandshake::sendPublicKey()
{ {
A2_LOG_DEBUG(fmt("CUID#%lld - Sending public key.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Sending public key.",
cuid_)); cuid_));
unsigned char* buf = new unsigned char[KEY_LENGTH+MAX_PAD_LENGTH]; unsigned char* buf = new unsigned char[KEY_LENGTH+MAX_PAD_LENGTH];
array_ptr<unsigned char> bufp(buf); array_ptr<unsigned char> bufp(buf);
@ -174,7 +174,7 @@ bool MSEHandshake::receivePublicKey()
wantRead_ = true; wantRead_ = true;
return false; return false;
} }
A2_LOG_DEBUG(fmt("CUID#%lld - public key received.", cuid_)); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - public key received.", cuid_));
// TODO handle exception. in catch, resbufLength = 0; // TODO handle exception. in catch, resbufLength = 0;
dh_->computeSecret(secret_, sizeof(secret_), rbuf_, KEY_LENGTH); dh_->computeSecret(secret_, sizeof(secret_), rbuf_, KEY_LENGTH);
// shift buffer // shift buffer
@ -269,7 +269,7 @@ uint16_t MSEHandshake::decodeLength16(const unsigned char* buffer)
void MSEHandshake::sendInitiatorStep2() void MSEHandshake::sendInitiatorStep2()
{ {
A2_LOG_DEBUG(fmt("CUID#%lld - Sending negotiation step2.", cuid_)); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Sending negotiation step2.", cuid_));
// Assuming no exception // Assuming no exception
unsigned char* md = new unsigned char[20]; unsigned char* md = new unsigned char[20];
createReq1Hash(md); createReq1Hash(md);
@ -338,7 +338,7 @@ bool MSEHandshake::findInitiatorVCMarker()
} }
} }
markerIndex_ = ptr-rbuf_; markerIndex_ = ptr-rbuf_;
A2_LOG_DEBUG(fmt("CUID#%lld - VC marker found at %lu", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - VC marker found at %lu",
cuid_, cuid_,
static_cast<unsigned long>(markerIndex_))); static_cast<unsigned long>(markerIndex_)));
verifyVC(rbuf_+markerIndex_); verifyVC(rbuf_+markerIndex_);
@ -358,18 +358,18 @@ bool MSEHandshake::receiveInitiatorCryptoSelectAndPadDLength()
decryptor_->encrypt(CRYPTO_BITFIELD_LENGTH, rbufptr, rbufptr); decryptor_->encrypt(CRYPTO_BITFIELD_LENGTH, rbufptr, rbufptr);
if(rbufptr[3]&CRYPTO_PLAIN_TEXT && if(rbufptr[3]&CRYPTO_PLAIN_TEXT &&
option_->get(PREF_BT_MIN_CRYPTO_LEVEL) == V_PLAIN) { option_->get(PREF_BT_MIN_CRYPTO_LEVEL) == V_PLAIN) {
A2_LOG_DEBUG(fmt("CUID#%lld - peer prefers plaintext.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - peer prefers plaintext.",
cuid_)); cuid_));
negotiatedCryptoType_ = CRYPTO_PLAIN_TEXT; negotiatedCryptoType_ = CRYPTO_PLAIN_TEXT;
} }
if(rbufptr[3]&CRYPTO_ARC4) { if(rbufptr[3]&CRYPTO_ARC4) {
A2_LOG_DEBUG(fmt("CUID#%lld - peer prefers ARC4", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - peer prefers ARC4",
cuid_)); cuid_));
negotiatedCryptoType_ = CRYPTO_ARC4; negotiatedCryptoType_ = CRYPTO_ARC4;
} }
if(negotiatedCryptoType_ == CRYPTO_NONE) { if(negotiatedCryptoType_ == CRYPTO_NONE) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt("CUID#%lld - No supported crypto type selected.", (fmt("CUID#%" PRId64 " - No supported crypto type selected.",
cuid_)); cuid_));
} }
// padD length // padD length
@ -412,7 +412,7 @@ bool MSEHandshake::findReceiverHashMarker()
} }
} }
markerIndex_ = ptr-rbuf_; markerIndex_ = ptr-rbuf_;
A2_LOG_DEBUG(fmt("CUID#%lld - Hash marker found at %lu.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Hash marker found at %lu.",
cuid_, cuid_,
static_cast<unsigned long>(markerIndex_))); static_cast<unsigned long>(markerIndex_)));
verifyReq1Hash(rbuf_+markerIndex_); verifyReq1Hash(rbuf_+markerIndex_);
@ -439,7 +439,7 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
const unsigned char* infohash = bittorrent::getInfoHash(*i); const unsigned char* infohash = bittorrent::getInfoHash(*i);
createReq23Hash(md, infohash); createReq23Hash(md, infohash);
if(memcmp(md, rbufptr, sizeof(md)) == 0) { if(memcmp(md, rbufptr, sizeof(md)) == 0) {
A2_LOG_DEBUG(fmt("CUID#%lld - info hash found: %s", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - info hash found: %s",
cuid_, cuid_,
util::toHex(infohash, INFO_HASH_LENGTH).c_str())); util::toHex(infohash, INFO_HASH_LENGTH).c_str()));
downloadContext = *i; downloadContext = *i;
@ -460,17 +460,17 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
// For now, choose ARC4. // For now, choose ARC4.
if(rbufptr[3]&CRYPTO_PLAIN_TEXT && if(rbufptr[3]&CRYPTO_PLAIN_TEXT &&
option_->get(PREF_BT_MIN_CRYPTO_LEVEL) == V_PLAIN) { option_->get(PREF_BT_MIN_CRYPTO_LEVEL) == V_PLAIN) {
A2_LOG_DEBUG(fmt("CUID#%lld - peer provides plaintext.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - peer provides plaintext.",
cuid_)); cuid_));
negotiatedCryptoType_ = CRYPTO_PLAIN_TEXT; negotiatedCryptoType_ = CRYPTO_PLAIN_TEXT;
} else if(rbufptr[3]&CRYPTO_ARC4) { } else if(rbufptr[3]&CRYPTO_ARC4) {
A2_LOG_DEBUG(fmt("CUID#%lld - peer provides ARC4.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - peer provides ARC4.",
cuid_)); cuid_));
negotiatedCryptoType_ = CRYPTO_ARC4; negotiatedCryptoType_ = CRYPTO_ARC4;
} }
if(negotiatedCryptoType_ == CRYPTO_NONE) { if(negotiatedCryptoType_ == CRYPTO_NONE) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt("CUID#%lld - No supported crypto type provided.", (fmt("CUID#%" PRId64 " - No supported crypto type provided.",
cuid_)); cuid_));
} }
// decrypt PadC length // decrypt PadC length
@ -491,7 +491,7 @@ bool MSEHandshake::receiveReceiverIALength()
if(iaLength_ > BtHandshakeMessage::MESSAGE_LENGTH) { if(iaLength_ > BtHandshakeMessage::MESSAGE_LENGTH) {
throw DL_ABORT_EX(fmt("Too large IA length length: %u", iaLength_)); throw DL_ABORT_EX(fmt("Too large IA length length: %u", iaLength_));
} }
A2_LOG_DEBUG(fmt("CUID#%lld - len(IA)=%u.", cuid_, iaLength_)); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - len(IA)=%u.", cuid_, iaLength_));
// shift rbuf_ // shift rbuf_
shiftBuffer(2); shiftBuffer(2);
return true; return true;
@ -509,7 +509,7 @@ bool MSEHandshake::receiveReceiverIA()
delete [] ia_; delete [] ia_;
ia_ = new unsigned char[iaLength_]; ia_ = new unsigned char[iaLength_];
decryptor_->encrypt(iaLength_, ia_, rbuf_); decryptor_->encrypt(iaLength_, ia_, rbuf_);
A2_LOG_DEBUG(fmt("CUID#%lld - IA received.", cuid_)); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - IA received.", cuid_));
// shift rbuf_ // shift rbuf_
shiftBuffer(iaLength_); shiftBuffer(iaLength_);
return true; return true;
@ -548,10 +548,10 @@ void MSEHandshake::sendReceiverStep2()
uint16_t MSEHandshake::verifyPadLength(const unsigned char* padlenbuf, const char* padName) uint16_t MSEHandshake::verifyPadLength(const unsigned char* padlenbuf, const char* padName)
{ {
A2_LOG_DEBUG(fmt("CUID#%lld - Verifying Pad length for %s", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Verifying Pad length for %s",
cuid_, padName)); cuid_, padName));
uint16_t padLength = decodeLength16(padlenbuf); uint16_t padLength = decodeLength16(padlenbuf);
A2_LOG_DEBUG(fmt("CUID#%lld - len(%s)=%u", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - len(%s)=%u",
cuid_, padName, padLength)); cuid_, padName, padLength));
if(padLength > 512) { if(padLength > 512) {
throw DL_ABORT_EX throw DL_ABORT_EX
@ -562,7 +562,7 @@ uint16_t MSEHandshake::verifyPadLength(const unsigned char* padlenbuf, const cha
void MSEHandshake::verifyVC(unsigned char* vcbuf) void MSEHandshake::verifyVC(unsigned char* vcbuf)
{ {
A2_LOG_DEBUG(fmt("CUID#%lld - Verifying VC.", cuid_)); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Verifying VC.", cuid_));
decryptor_->encrypt(VC_LENGTH, vcbuf, vcbuf); decryptor_->encrypt(VC_LENGTH, vcbuf, vcbuf);
if(memcmp(VC, vcbuf, VC_LENGTH) != 0) { if(memcmp(VC, vcbuf, VC_LENGTH) != 0) {
throw DL_ABORT_EX throw DL_ABORT_EX
@ -572,7 +572,7 @@ void MSEHandshake::verifyVC(unsigned char* vcbuf)
void MSEHandshake::verifyReq1Hash(const unsigned char* req1buf) void MSEHandshake::verifyReq1Hash(const unsigned char* req1buf)
{ {
A2_LOG_DEBUG(fmt("CUID#%lld - Verifying req hash.", cuid_)); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Verifying req hash.", cuid_));
unsigned char md[20]; unsigned char md[20];
createReq1Hash(md); createReq1Hash(md);
if(memcmp(md, req1buf, sizeof(md)) != 0) { if(memcmp(md, req1buf, sizeof(md)) != 0) {

View file

@ -186,9 +186,9 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
(fileEntry->getOffset()+fileEntry->getLength()-1)/ (fileEntry->getOffset()+fileEntry->getLength()-1)/
pieceLength_*pieceLength_; pieceLength_*pieceLength_;
A2_LOG_DEBUG(fmt("Checking adjacent backward file to %s" A2_LOG_DEBUG(fmt("Checking adjacent backward file to %s"
" whose lastPieceStartOffset+pieceLength_=%lld", " whose lastPieceStartOffset+pieceLength_=%" PRId64 "",
fileEntry->getPath().c_str(), fileEntry->getPath().c_str(),
static_cast<long long int> static_cast<int64_t>
(lastPieceStartOffset+pieceLength_))); (lastPieceStartOffset+pieceLength_)));
++itr; ++itr;
// adjacent backward files are not needed to be allocated. They // adjacent backward files are not needed to be allocated. They
@ -197,9 +197,9 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
(!(*itr)->getFileEntry()->isRequested() || (!(*itr)->getFileEntry()->isRequested() ||
(*itr)->getFileEntry()->getLength() == 0); ++itr) { (*itr)->getFileEntry()->getLength() == 0); ++itr) {
A2_LOG_DEBUG A2_LOG_DEBUG
(fmt("file=%s, offset=%lld", (fmt("file=%s, offset=%" PRId64 "",
(*itr)->getFileEntry()->getPath().c_str(), (*itr)->getFileEntry()->getPath().c_str(),
static_cast<long long int> static_cast<int64_t>
((*itr)->getFileEntry()->getOffset()))); ((*itr)->getFileEntry()->getOffset())));
if((*itr)->getFileEntry()->getOffset() < if((*itr)->getFileEntry()->getOffset() <
static_cast<off_t>(lastPieceStartOffset+pieceLength_)) { static_cast<off_t>(lastPieceStartOffset+pieceLength_)) {
@ -348,7 +348,7 @@ DiskWriterEntries::const_iterator findFirstDiskWriterEntry
// In case when offset is out-of-range // In case when offset is out-of-range
if(!isInRange(*first, offset)) { if(!isInRange(*first, offset)) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt(EX_FILE_OFFSET_OUT_OF_RANGE, static_cast<long long int>(offset))); (fmt(EX_FILE_OFFSET_OUT_OF_RANGE, static_cast<int64_t>(offset)));
} }
return first; return first;
} }
@ -359,8 +359,8 @@ void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
off_t offset) off_t offset)
{ {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt("DiskWriter for offset=%lld, filename=%s is not opened.", (fmt("DiskWriter for offset=%" PRId64 ", filename=%s is not opened.",
static_cast<long long int>(offset), static_cast<int64_t>(offset),
e->getFilePath().c_str())); e->getFilePath().c_str()));
} }
} // namespace } // namespace

View file

@ -165,15 +165,12 @@ void NumberOptionHandler::parseArg(Option& option, int64_t number)
std::string msg = pref_->k; std::string msg = pref_->k;
msg += " "; msg += " ";
if(min_ == -1 && max_ != -1) { if(min_ == -1 && max_ != -1) {
msg += fmt(_("must be smaller than or equal to %lld."), msg += fmt(_("must be smaller than or equal to %" PRId64 "."), max_);
static_cast<long long int>(max_));
} else if(min_ != -1 && max_ != -1) { } else if(min_ != -1 && max_ != -1) {
msg += fmt(_("must be between %lld and %lld."), msg += fmt(_("must be between %" PRId64 " and %" PRId64 "."),
static_cast<long long int>(min_), min_, max_);
static_cast<long long int>(max_));
} else if(min_ != -1 && max_ == -1) { } else if(min_ != -1 && max_ == -1) {
msg += fmt(_("must be greater than or equal to %lld."), msg += fmt(_("must be greater than or equal to %" PRId64 "."), min_);
static_cast<long long int>(min_));
} else { } else {
msg += _("must be a number."); msg += _("must be a number.");
} }

View file

@ -78,7 +78,7 @@ PeerAbstractCommand::~PeerAbstractCommand()
bool PeerAbstractCommand::execute() bool PeerAbstractCommand::execute()
{ {
A2_LOG_DEBUG(fmt("CUID#%lld -" A2_LOG_DEBUG(fmt("CUID#%" PRId64 " -"
" socket: read:%d, write:%d, hup:%d, err:%d, noCheck:%d", " socket: read:%d, write:%d, hup:%d, err:%d, noCheck:%d",
getCuid(), getCuid(),
readEventEnabled(), writeEventEnabled(), readEventEnabled(), writeEventEnabled(),

View file

@ -201,7 +201,7 @@ bool PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength,
if(remaining == 0 && !socket_->wantRead() && !socket_->wantWrite()) { if(remaining == 0 && !socket_->wantRead() && !socket_->wantWrite()) {
// we got EOF // we got EOF
A2_LOG_DEBUG A2_LOG_DEBUG
(fmt("CUID#%lld - In PeerConnection::receiveHandshake(), remain=%lu", (fmt("CUID#%" PRId64 " - In PeerConnection::receiveHandshake(), remain=%lu",
cuid_, cuid_,
static_cast<unsigned long>(temp))); static_cast<unsigned long>(temp)));
peer_->setDisconnectedGracefully(true); peer_->setDisconnectedGracefully(true);

View file

@ -124,7 +124,7 @@ bool PeerListenCommand::execute() {
A2_LOG_DEBUG(fmt("Accepted the connection from %s:%u.", A2_LOG_DEBUG(fmt("Accepted the connection from %s:%u.",
peer->getIPAddress().c_str(), peer->getIPAddress().c_str(),
peer->getPort())); peer->getPort()));
A2_LOG_DEBUG(fmt("Added CUID#%lld to receive BitTorrent/MSE handshake.", A2_LOG_DEBUG(fmt("Added CUID#%" PRId64 " to receive BitTorrent/MSE handshake.",
cuid)); cuid));
} catch(RecoverableException& ex) { } catch(RecoverableException& ex) {
A2_LOG_DEBUG_EX(fmt(MSG_ACCEPT_FAILURE, A2_LOG_DEBUG_EX(fmt(MSG_ACCEPT_FAILURE,

View file

@ -396,9 +396,9 @@ void RequestGroup::createInitialCommand
// truncate the file to downloadContext_->getTotalLength() // truncate the file to downloadContext_->getTotalLength()
A2_LOG_DEBUG A2_LOG_DEBUG
(fmt("File size not match. File is opened in writable" (fmt("File size not match. File is opened in writable"
" mode. Expected:%lld Actual:%lld", " mode. Expected:%" PRId64 " Actual:%" PRId64 "",
static_cast<long long int>(downloadContext_->getTotalLength()), static_cast<int64_t>(downloadContext_->getTotalLength()),
static_cast<long long int>(actualFileSize))); static_cast<int64_t>(actualFileSize)));
} }
} }
// Call Load, Save and file allocation command here // Call Load, Save and file allocation command here
@ -906,8 +906,8 @@ void RequestGroup::validateTotalLength(off_t expectedTotalLength,
if(expectedTotalLength != actualTotalLength) { if(expectedTotalLength != actualTotalLength) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt(EX_SIZE_MISMATCH, (fmt(EX_SIZE_MISMATCH,
static_cast<long long int>(expectedTotalLength), static_cast<int64_t>(expectedTotalLength),
static_cast<long long int>(actualTotalLength))); static_cast<int64_t>(actualTotalLength)));
} }
} }
@ -961,7 +961,7 @@ void RequestGroup::decreaseNumCommand()
{ {
--numCommand_; --numCommand_;
if(!numCommand_ && requestGroupMan_) { if(!numCommand_ && requestGroupMan_) {
A2_LOG_DEBUG(fmt("GID#%lld - Request queue check", gid_)); A2_LOG_DEBUG(fmt("GID#%" PRId64 " - Request queue check", gid_));
requestGroupMan_->requestQueueCheck(); requestGroupMan_->requestQueueCheck();
} }
} }
@ -1156,7 +1156,7 @@ bool RequestGroup::needsFileAllocation() const
DownloadResultHandle RequestGroup::createDownloadResult() const DownloadResultHandle RequestGroup::createDownloadResult() const
{ {
A2_LOG_DEBUG(fmt("GID#%lld - Creating DownloadResult.", gid_)); A2_LOG_DEBUG(fmt("GID#%" PRId64 " - Creating DownloadResult.", gid_));
TransferStat st = calculateStat(); TransferStat st = calculateStat();
SharedHandle<DownloadResult> res(new DownloadResult()); SharedHandle<DownloadResult> res(new DownloadResult());
res->gid = gid_; res->gid = gid_;

View file

@ -73,8 +73,7 @@ class BtRuntime;
class PeerStorage; class PeerStorage;
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
// To make %lld happy, we use long long int instead of int64_t. typedef int64_t a2_gid_t;
typedef long long int a2_gid_t;
class RequestGroup { class RequestGroup {
public: public:

View file

@ -207,7 +207,7 @@ size_t RequestGroupMan::changeReservedGroupPosition
std::deque<SharedHandle<RequestGroup> >::iterator i = std::deque<SharedHandle<RequestGroup> >::iterator i =
findByGID(reservedGroups_.begin(), reservedGroups_.end(), gid); findByGID(reservedGroups_.begin(), reservedGroups_.end(), gid);
if(i == reservedGroups_.end()) { if(i == reservedGroups_.end()) {
throw DL_ABORT_EX(fmt("GID#%lld not found in the waiting queue.", gid)); throw DL_ABORT_EX(fmt("GID#%" PRId64 " not found in the waiting queue.", gid));
} }
SharedHandle<RequestGroup> rg = *i; SharedHandle<RequestGroup> rg = *i;
const size_t maxPos = reservedGroups_.size()-1; const size_t maxPos = reservedGroups_.size()-1;
@ -387,7 +387,7 @@ public:
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
} else { } else {
A2_LOG_NOTICE A2_LOG_NOTICE
(fmt(_("Download GID#%lld not complete: %s"), (fmt(_("Download GID#%" PRId64 " not complete: %s"),
group->getGID(), group->getGID(),
group->getDownloadContext()->getBasePath().c_str())); group->getDownloadContext()->getBasePath().c_str()));
group->saveControlFile(); group->saveControlFile();

View file

@ -381,12 +381,12 @@ SharedHandle<ValueBase> removeDownload
if(!group) { if(!group) {
group = e->getRequestGroupMan()->findReservedGroup(gid); group = e->getRequestGroupMan()->findReservedGroup(gid);
if(!group) { if(!group) {
throw DL_ABORT_EX(fmt("Active Download not found for GID#%lld", gid)); throw DL_ABORT_EX(fmt("Active Download not found for GID#%" PRId64 "", gid));
} }
if(group->isDependencyResolved()) { if(group->isDependencyResolved()) {
e->getRequestGroupMan()->removeReservedGroup(gid); e->getRequestGroupMan()->removeReservedGroup(gid);
} else { } else {
throw DL_ABORT_EX(fmt("GID#%lld cannot be removed now", gid)); throw DL_ABORT_EX(fmt("GID#%" PRId64 " cannot be removed now", gid));
} }
} else { } else {
if(forceRemove) { if(forceRemove) {
@ -456,7 +456,7 @@ SharedHandle<ValueBase> pauseDownload
e->setRefreshInterval(0); e->setRefreshInterval(0);
return createGIDResponse(gid); return createGIDResponse(gid);
} else { } else {
throw DL_ABORT_EX(fmt("GID#%lld cannot be paused now", gid)); throw DL_ABORT_EX(fmt("GID#%" PRId64 " cannot be paused now", gid));
} }
} }
} // namespace } // namespace
@ -520,7 +520,7 @@ SharedHandle<ValueBase> UnpauseRpcMethod::process
SharedHandle<RequestGroup> group = SharedHandle<RequestGroup> group =
e->getRequestGroupMan()->findReservedGroup(gid); e->getRequestGroupMan()->findReservedGroup(gid);
if(!group || !group->isPauseRequested()) { if(!group || !group->isPauseRequested()) {
throw DL_ABORT_EX(fmt("GID#%lld cannot be unpaused now", gid)); throw DL_ABORT_EX(fmt("GID#%" PRId64 " cannot be unpaused now", gid));
} else { } else {
group->setPauseRequested(false); group->setPauseRequested(false);
e->getRequestGroupMan()->requestQueueCheck(); e->getRequestGroupMan()->requestQueueCheck();
@ -923,7 +923,7 @@ SharedHandle<ValueBase> GetFilesRpcMethod::process
SharedHandle<DownloadResult> dr = SharedHandle<DownloadResult> dr =
e->getRequestGroupMan()->findDownloadResult(gid); e->getRequestGroupMan()->findDownloadResult(gid);
if(!dr) { if(!dr) {
throw DL_ABORT_EX(fmt("No file data is available for GID#%lld", gid)); throw DL_ABORT_EX(fmt("No file data is available for GID#%" PRId64 "", gid));
} else { } else {
createFileEntry(files, dr->fileEntries.begin(), dr->fileEntries.end(), createFileEntry(files, dr->fileEntries.begin(), dr->fileEntries.end(),
dr->totalLength, dr->pieceLength, dr->bitfield); dr->totalLength, dr->pieceLength, dr->bitfield);
@ -950,7 +950,7 @@ SharedHandle<ValueBase> GetUrisRpcMethod::process
SharedHandle<RequestGroup> group = SharedHandle<RequestGroup> group =
findRequestGroup(e->getRequestGroupMan(), gid); findRequestGroup(e->getRequestGroupMan(), gid);
if(!group) { if(!group) {
throw DL_ABORT_EX(fmt("No URI data is available for GID#%lld", gid)); throw DL_ABORT_EX(fmt("No URI data is available for GID#%" PRId64 "", gid));
} }
SharedHandle<List> uriList = List::g(); SharedHandle<List> uriList = List::g();
// TODO Current implementation just returns first FileEntry's URIs. // TODO Current implementation just returns first FileEntry's URIs.
@ -970,7 +970,7 @@ SharedHandle<ValueBase> GetPeersRpcMethod::process
SharedHandle<RequestGroup> group = SharedHandle<RequestGroup> group =
findRequestGroup(e->getRequestGroupMan(), gid); findRequestGroup(e->getRequestGroupMan(), gid);
if(!group) { if(!group) {
throw DL_ABORT_EX(fmt("No peer data is available for GID#%lld", gid)); throw DL_ABORT_EX(fmt("No peer data is available for GID#%" PRId64 "", gid));
} }
SharedHandle<List> peers = List::g(); SharedHandle<List> peers = List::g();
const SharedHandle<BtObject>& btObject = const SharedHandle<BtObject>& btObject =
@ -1003,7 +1003,7 @@ SharedHandle<ValueBase> TellStatusRpcMethod::process
SharedHandle<DownloadResult> ds = SharedHandle<DownloadResult> ds =
e->getRequestGroupMan()->findDownloadResult(gid); e->getRequestGroupMan()->findDownloadResult(gid);
if(!ds) { if(!ds) {
throw DL_ABORT_EX(fmt("No such download for GID#%lld", gid)); throw DL_ABORT_EX(fmt("No such download for GID#%" PRId64 "", gid));
} }
gatherStoppedDownload(entryDict, ds, keys); gatherStoppedDownload(entryDict, ds, keys);
} else { } else {
@ -1097,7 +1097,7 @@ SharedHandle<ValueBase> RemoveDownloadResultRpcMethod::process
a2_gid_t gid = str2Gid(gidParam); a2_gid_t gid = str2Gid(gidParam);
if(!e->getRequestGroupMan()->removeDownloadResult(gid)) { if(!e->getRequestGroupMan()->removeDownloadResult(gid)) {
throw DL_ABORT_EX(fmt("Could not remove download result of GID#%lld", gid)); throw DL_ABORT_EX(fmt("Could not remove download result of GID#%" PRId64 "", gid));
} }
return VLB_OK; return VLB_OK;
} }
@ -1200,7 +1200,7 @@ SharedHandle<ValueBase> ChangeOptionRpcMethod::process
gatherChangeableOptionForReserved(&option, optsParam); gatherChangeableOptionForReserved(&option, optsParam);
changeOption(group, option, e); changeOption(group, option, e);
} else { } else {
throw DL_ABORT_EX(fmt("Cannot change option for GID#%lld", gid)); throw DL_ABORT_EX(fmt("Cannot change option for GID#%" PRId64 "", gid));
} }
} }
return VLB_OK; return VLB_OK;
@ -1289,7 +1289,7 @@ SharedHandle<ValueBase> GetOptionRpcMethod::process
SharedHandle<RequestGroup> group = SharedHandle<RequestGroup> group =
findRequestGroup(e->getRequestGroupMan(), gid); findRequestGroup(e->getRequestGroupMan(), gid);
if(!group) { if(!group) {
throw DL_ABORT_EX(fmt("Cannot get option for GID#%lld", gid)); throw DL_ABORT_EX(fmt("Cannot get option for GID#%" PRId64 "", gid));
} }
SharedHandle<Dict> result = Dict::g(); SharedHandle<Dict> result = Dict::g();
SharedHandle<Option> option = group->getOption(); SharedHandle<Option> option = group->getOption();
@ -1357,7 +1357,7 @@ SharedHandle<ValueBase> GetServersRpcMethod::process
SharedHandle<RequestGroup> group = SharedHandle<RequestGroup> group =
e->getRequestGroupMan()->findRequestGroup(gid); e->getRequestGroupMan()->findRequestGroup(gid);
if(!group) { if(!group) {
throw DL_ABORT_EX(fmt("No active download for GID#%lld", gid)); throw DL_ABORT_EX(fmt("No active download for GID#%" PRId64 "", gid));
} }
const SharedHandle<DownloadContext>& dctx = group->getDownloadContext(); const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries(); const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();
@ -1404,7 +1404,7 @@ SharedHandle<ValueBase> ChangeUriRpcMethod::process
SharedHandle<RequestGroup> group = SharedHandle<RequestGroup> group =
findRequestGroup(e->getRequestGroupMan(), gid); findRequestGroup(e->getRequestGroupMan(), gid);
if(!group) { if(!group) {
throw DL_ABORT_EX(fmt("Cannot remove URIs from GID#%lld", gid)); throw DL_ABORT_EX(fmt("Cannot remove URIs from GID#%" PRId64 "", gid));
} }
const SharedHandle<DownloadContext>& dctx = group->getDownloadContext(); const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries(); const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();

View file

@ -120,7 +120,7 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
if(!piece) { if(!piece) {
return SharedHandle<Segment>(); return SharedHandle<Segment>();
} }
A2_LOG_DEBUG(fmt("Attach segment#%lu to CUID#%lld.", A2_LOG_DEBUG(fmt("Attach segment#%lu to CUID#%" PRId64 ".",
static_cast<unsigned long>(piece->getIndex()), static_cast<unsigned long>(piece->getIndex()),
cuid)); cuid));
piece->setUsedBySegment(true); piece->setUsedBySegment(true);
@ -468,10 +468,10 @@ size_t SegmentMan::countFreePieceFrom(size_t index) const
void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry) void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry)
{ {
A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%lld, length=%lld", A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%" PRId64 ", length=%" PRId64 "",
fileEntry->getPath().c_str(), fileEntry->getPath().c_str(),
static_cast<long long int>(fileEntry->getOffset()), static_cast<int64_t>(fileEntry->getOffset()),
static_cast<long long int>(fileEntry->getLength()))); static_cast<int64_t>(fileEntry->getLength())));
ignoreBitfield_.addFilter(fileEntry->getOffset(), fileEntry->getLength()); ignoreBitfield_.addFilter(fileEntry->getOffset(), fileEntry->getLength());
} }

View file

@ -175,7 +175,7 @@ void TrackerWatcherCommand::processTrackerResponse
command->setPeerStorage(peerStorage_); command->setPeerStorage(peerStorage_);
command->setPieceStorage(pieceStorage_); command->setPieceStorage(pieceStorage_);
e_->addCommand(command); e_->addCommand(command);
A2_LOG_DEBUG(fmt("CUID#%lld - Adding new command CUID#%lld", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Adding new command CUID#%" PRId64 "",
getCuid(), peer->usedBy())); getCuid(), peer->usedBy()));
} }
} }
@ -246,7 +246,7 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
rg->setFileAllocationEnabled(false); rg->setFileAllocationEnabled(false);
rg->setPreLocalFileCheckEnabled(false); rg->setPreLocalFileCheckEnabled(false);
util::removeMetalinkContentTypes(rg); util::removeMetalinkContentTypes(rg);
A2_LOG_INFO(fmt("Creating tracker request group GID#%lld", rg->getGID())); A2_LOG_INFO(fmt("Creating tracker request group GID#%" PRId64 "", rg->getGID()));
return rg; return rg;
} }

View file

@ -118,7 +118,7 @@ void WatchProcessCommand::process()
#endif #endif
if(!waiting) { if(!waiting) {
A2_LOG_INFO A2_LOG_INFO
(fmt("CUID#%lld - Process %u is not running. Commencing shutdown.", (fmt("CUID#%" PRId64 " - Process %u is not running. Commencing shutdown.",
getCuid(), pid_)); getCuid(), pid_));
if(forceHalt_) { if(forceHalt_) {
getDownloadEngine()->requestForceHalt(); getDownloadEngine()->requestForceHalt();

View file

@ -91,9 +91,9 @@ bool WebSocketInteractionCommand::execute()
} }
if(wsSession_->onReadEvent() == -1 || wsSession_->onWriteEvent() == -1) { if(wsSession_->onReadEvent() == -1 || wsSession_->onWriteEvent() == -1) {
if(wsSession_->closeSent() || wsSession_->closeReceived()) { if(wsSession_->closeSent() || wsSession_->closeReceived()) {
A2_LOG_INFO(fmt("CUID#%lld - WebSocket session terminated.", getCuid())); A2_LOG_INFO(fmt("CUID#%" PRId64 " - WebSocket session terminated.", getCuid()));
} else { } else {
A2_LOG_INFO(fmt("CUID#%lld - WebSocket session terminated" A2_LOG_INFO(fmt("CUID#%" PRId64 " - WebSocket session terminated"
" (Possibly due to EOF).", getCuid())); " (Possibly due to EOF).", getCuid()));
} }
return true; return true;

View file

@ -250,8 +250,7 @@ void extractFileEntries
} }
length += fileLengthData->i(); length += fileLengthData->i();
if(length > std::numeric_limits<off_t>::max()) { if(length > std::numeric_limits<off_t>::max()) {
throw DOWNLOAD_FAILURE_EXCEPTION throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, length));
(fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(length)));
} }
std::string pathKey; std::string pathKey;
if(fileDict->containsKey(C_PATH_UTF8)) { if(fileDict->containsKey(C_PATH_UTF8)) {
@ -310,8 +309,7 @@ void extractFileEntries
} }
int64_t totalLength = lengthData->i(); int64_t totalLength = lengthData->i();
if(totalLength > std::numeric_limits<off_t>::max()) { if(totalLength > std::numeric_limits<off_t>::max()) {
throw DOWNLOAD_FAILURE_EXCEPTION throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, totalLength));
(fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(totalLength)));
} }
// For each uri in urlList, if it ends with '/', then // For each uri in urlList, if it ends with '/', then
// concatenate name to it. Specification just says so. // concatenate name to it. Specification just says so.

View file

@ -75,5 +75,8 @@
#define __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS
// included here for compatibility issues with old compiler/libraries. // included here for compatibility issues with old compiler/libraries.
#include <stdint.h> #include <stdint.h>
// For PRId64
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#endif // D_COMMON_H #endif // D_COMMON_H

View file

@ -38,70 +38,70 @@
#include "common.h" #include "common.h"
#define MSG_SEGMENT_DOWNLOAD_COMPLETED \ #define MSG_SEGMENT_DOWNLOAD_COMPLETED \
"CUID#%lld - The download for one segment completed successfully." "CUID#%" PRId64 " - The download for one segment completed successfully."
#define MSG_NO_SEGMENT_AVAILABLE "CUID#%lld - No segment available." #define MSG_NO_SEGMENT_AVAILABLE "CUID#%" PRId64 " - No segment available."
#define MSG_CONNECTING_TO_SERVER "CUID#%lld - Connecting to %s:%d" #define MSG_CONNECTING_TO_SERVER "CUID#%" PRId64 " - Connecting to %s:%d"
#define MSG_REDIRECT "CUID#%lld - Redirecting to %s" #define MSG_REDIRECT "CUID#%" PRId64 " - Redirecting to %s"
#define MSG_SENDING_REQUEST "CUID#%lld - Requesting:\n%s" #define MSG_SENDING_REQUEST "CUID#%" PRId64 " - Requesting:\n%s"
#define MSG_RECEIVE_RESPONSE "CUID#%lld - Response received:\n%s" #define MSG_RECEIVE_RESPONSE "CUID#%" PRId64 " - Response received:\n%s"
#define MSG_DOWNLOAD_ABORTED "CUID#%lld - Download aborted. URI=%s" #define MSG_DOWNLOAD_ABORTED "CUID#%" PRId64 " - Download aborted. URI=%s"
#define MSG_RESTARTING_DOWNLOAD "CUID#%lld - Restarting the download. URI=%s" #define MSG_RESTARTING_DOWNLOAD "CUID#%" PRId64 " - Restarting the download. URI=%s"
#define MSG_TORRENT_DOWNLOAD_ABORTED "CUID#%lld - Download aborted." #define MSG_TORRENT_DOWNLOAD_ABORTED "CUID#%" PRId64 " - Download aborted."
#define MSG_MAX_TRY \ #define MSG_MAX_TRY \
"CUID#%lld - %d times attempted, but no success. Download aborted." "CUID#%" PRId64 " - %d times attempted, but no success. Download aborted."
#define MSG_SEND_PEER_MESSAGE "CUID#%lld - To: %s:%d %s" #define MSG_SEND_PEER_MESSAGE "CUID#%" PRId64 " - To: %s:%d %s"
#define MSG_RECEIVE_PEER_MESSAGE "CUID#%lld - From: %s:%d %s" #define MSG_RECEIVE_PEER_MESSAGE "CUID#%" PRId64 " - From: %s:%d %s"
#define MSG_GOT_NEW_PIECE "CUID#%lld - we got new piece. index=%lu" #define MSG_GOT_NEW_PIECE "CUID#%" PRId64 " - we got new piece. index=%lu"
#define MSG_GOT_WRONG_PIECE "CUID#%lld - we got wrong piece. index=%lu" #define MSG_GOT_WRONG_PIECE "CUID#%" PRId64 " - we got wrong piece. index=%lu"
#define MSG_DOWNLOAD_NOT_COMPLETE "CUID#%lld - Download not complete: %s" #define MSG_DOWNLOAD_NOT_COMPLETE "CUID#%" PRId64 " - Download not complete: %s"
#define MSG_DOWNLOAD_ALREADY_COMPLETED _("GID#%lld - Download has already completed: %s") #define MSG_DOWNLOAD_ALREADY_COMPLETED _("GID#%" PRId64 " - Download has already completed: %s")
#define MSG_RESOLVING_HOSTNAME "CUID#%lld - Resolving hostname %s" #define MSG_RESOLVING_HOSTNAME "CUID#%" PRId64 " - Resolving hostname %s"
#define MSG_NAME_RESOLUTION_COMPLETE \ #define MSG_NAME_RESOLUTION_COMPLETE \
"CUID#%lld - Name resolution complete: %s -> %s" "CUID#%" PRId64 " - Name resolution complete: %s -> %s"
#define MSG_NAME_RESOLUTION_FAILED \ #define MSG_NAME_RESOLUTION_FAILED \
"CUID#%lld - Name resolution for %s failed:%s" "CUID#%" PRId64 " - Name resolution for %s failed:%s"
#define MSG_DNS_CACHE_HIT "CUID#%lld - DNS cache hit: %s -> %s" #define MSG_DNS_CACHE_HIT "CUID#%" PRId64 " - DNS cache hit: %s -> %s"
#define MSG_CONNECTING_TO_PEER "CUID#%lld - Connecting to the peer %s" #define MSG_CONNECTING_TO_PEER "CUID#%" PRId64 " - Connecting to the peer %s"
#define MSG_PIECE_RECEIVED \ #define MSG_PIECE_RECEIVED \
"CUID#%lld - Piece received. index=%lu, begin=%d, length=%d, offset=%lld," \ "CUID#%" PRId64 " - Piece received. index=%lu, begin=%d, length=%d, offset=%" PRId64 "," \
" blockIndex=%lu" " blockIndex=%lu"
#define MSG_PIECE_BITFIELD "CUID#%lld - Piece bitfield %s" #define MSG_PIECE_BITFIELD "CUID#%" PRId64 " - Piece bitfield %s"
#define MSG_REJECT_PIECE_CHOKED \ #define MSG_REJECT_PIECE_CHOKED \
"CUID#%lld - Reject piece message in queue because the peer has been" \ "CUID#%" PRId64 " - Reject piece message in queue because the peer has been" \
" choked. index=%lu, begin=%d, length=%d" " choked. index=%lu, begin=%d, length=%d"
#define MSG_REJECT_PIECE_CANCEL \ #define MSG_REJECT_PIECE_CANCEL \
"CUID#%lld - Reject piece message in queue because cancel message received." \ "CUID#%" PRId64 " - Reject piece message in queue because cancel message received." \
" index=%lu, begin=%d, length=%d" " index=%lu, begin=%d, length=%d"
#define MSG_FILE_VALIDATION_FAILURE \ #define MSG_FILE_VALIDATION_FAILURE \
"CUID#%lld - Exception caught while validating file integrity." "CUID#%" PRId64 " - Exception caught while validating file integrity."
#define MSG_PEER_INTERESTED "CUID#%lld - Interested in the peer" #define MSG_PEER_INTERESTED "CUID#%" PRId64 " - Interested in the peer"
#define MSG_PEER_NOT_INTERESTED "CUID#%lld - Not interested in the peer" #define MSG_PEER_NOT_INTERESTED "CUID#%" PRId64 " - Not interested in the peer"
#define MSG_DELETING_REQUEST_SLOT "CUID#%lld - Deleting request slot" \ #define MSG_DELETING_REQUEST_SLOT "CUID#%" PRId64 " - Deleting request slot" \
" index=%lu, begin=%d, blockIndex=%lu" " index=%lu, begin=%d, blockIndex=%lu"
#define MSG_DELETING_REQUEST_SLOT_CHOKED "CUID#%lld - Deleting request slot" \ #define MSG_DELETING_REQUEST_SLOT_CHOKED "CUID#%" PRId64 " - Deleting request slot" \
" index=%lu, begin=%d, blockIndex=%lu because localhost got choked." " index=%lu, begin=%d, blockIndex=%lu because localhost got choked."
#define MSG_DELETING_REQUEST_SLOT_TIMEOUT "CUID#%lld - Deleting request slot" \ #define MSG_DELETING_REQUEST_SLOT_TIMEOUT "CUID#%" PRId64 " - Deleting request slot" \
" index=%lu, begin=%d, blockIndex=%lu because of time out" " index=%lu, begin=%d, blockIndex=%lu because of time out"
#define MSG_DELETING_REQUEST_SLOT_ACQUIRED "CUID#%lld - Deleting request slot" \ #define MSG_DELETING_REQUEST_SLOT_ACQUIRED "CUID#%" PRId64 " - Deleting request slot" \
" index=%lu, begin=%d, blockIndex=%lu because the block has been acquired." " index=%lu, begin=%d, blockIndex=%lu because the block has been acquired."
#define MSG_FAST_EXTENSION_ENABLED "CUID#%lld - Fast extension enabled." #define MSG_FAST_EXTENSION_ENABLED "CUID#%" PRId64 " - Fast extension enabled."
#define MSG_EXTENDED_MESSAGING_ENABLED "CUID#%lld - Extended Messaging enabled." #define MSG_EXTENDED_MESSAGING_ENABLED "CUID#%" PRId64 " - Extended Messaging enabled."
#define MSG_FILE_ALLOCATION_FAILURE \ #define MSG_FILE_ALLOCATION_FAILURE \
"CUID#%lld - Exception caught while allocating file space." "CUID#%" PRId64 " - Exception caught while allocating file space."
#define MSG_CONTENT_DISPOSITION_DETECTED \ #define MSG_CONTENT_DISPOSITION_DETECTED \
"CUID#%lld - Content-Disposition detected. Use %s as filename" "CUID#%" PRId64 " - Content-Disposition detected. Use %s as filename"
#define MSG_PEER_BANNED "CUID#%lld - Peer %s:%d banned." #define MSG_PEER_BANNED "CUID#%" PRId64 " - Peer %s:%d banned."
#define MSG_LISTENING_PORT \ #define MSG_LISTENING_PORT \
"CUID#%lld - Using port %d for accepting new connections" "CUID#%" PRId64 " - Using port %d for accepting new connections"
#define MSG_BIND_FAILURE "CUID#%lld - An error occurred while binding port=%d" #define MSG_BIND_FAILURE "CUID#%" PRId64 " - An error occurred while binding port=%d"
#define MSG_INCOMING_PEER_CONNECTION \ #define MSG_INCOMING_PEER_CONNECTION \
"CUID#%lld - Incoming connection, adding new command CUID#%lld" "CUID#%" PRId64 " - Incoming connection, adding new command CUID#%" PRId64 ""
#define MSG_ACCEPT_FAILURE "CUID#%lld - Error in accepting connection" #define MSG_ACCEPT_FAILURE "CUID#%" PRId64 " - Error in accepting connection"
#define MSG_TRACKER_RESPONSE_PROCESSING_FAILED \ #define MSG_TRACKER_RESPONSE_PROCESSING_FAILED \
"CUID#%lld - Error occurred while processing tracker response." "CUID#%" PRId64 " - Error occurred while processing tracker response."
#define MSG_DHT_ENABLED_PEER "CUID#%lld - The peer is DHT-enabled." #define MSG_DHT_ENABLED_PEER "CUID#%" PRId64 " - The peer is DHT-enabled."
#define MSG_CONNECT_FAILED_AND_RETRY \ #define MSG_CONNECT_FAILED_AND_RETRY \
"CUID#%lld - Could not to connect to %s:%u. Trying another address" "CUID#%" PRId64 " - Could not to connect to %s:%u. Trying another address"
#define MSG_UNRECOGNIZED_URI _("Unrecognized URI or unsupported protocol: %s") #define MSG_UNRECOGNIZED_URI _("Unrecognized URI or unsupported protocol: %s")
#define MSG_TRACKER_WARNING_MESSAGE _("Tracker returned warning message: %s") #define MSG_TRACKER_WARNING_MESSAGE _("Tracker returned warning message: %s")
@ -125,9 +125,9 @@
#define MSG_DOWNLOAD_COMPLETED _("The download was complete.") #define MSG_DOWNLOAD_COMPLETED _("The download was complete.")
#define MSG_REMOVED_HAVE_ENTRY _("Removed %lu have entries.") #define MSG_REMOVED_HAVE_ENTRY _("Removed %lu have entries.")
#define MSG_VALIDATING_FILE _("Validating file %s") #define MSG_VALIDATING_FILE _("Validating file %s")
#define MSG_ALLOCATION_COMPLETED "%ld seconds to allocate %lld byte(s)" #define MSG_ALLOCATION_COMPLETED "%ld seconds to allocate %" PRId64 " byte(s)"
#define MSG_FILE_ALLOCATION_DISPATCH \ #define MSG_FILE_ALLOCATION_DISPATCH \
"Dispatching FileAllocationCommand for CUID#%lld." "Dispatching FileAllocationCommand for CUID#%" PRId64 "."
#define MSG_METALINK_QUEUEING _("Metalink: Queueing %s for download.") #define MSG_METALINK_QUEUEING _("Metalink: Queueing %s for download.")
#define MSG_FILE_DOWNLOAD_COMPLETED _("Download complete: %s") #define MSG_FILE_DOWNLOAD_COMPLETED _("Download complete: %s")
#define MSG_SEEDING_END _("Seeding is over.") #define MSG_SEEDING_END _("Seeding is over.")
@ -195,7 +195,7 @@
#define MSG_DIR_TRAVERSAL_DETECTED _("Detected directory traversal directive in %s") #define MSG_DIR_TRAVERSAL_DETECTED _("Detected directory traversal directive in %s")
#define MSG_HASH_CHECK_NOT_DONE \ #define MSG_HASH_CHECK_NOT_DONE \
"File has already been downloaded but hash check has not been done yet." "File has already been downloaded but hash check has not been done yet."
#define MSG_REMOVING_UNSELECTED_FILE _("GID#%lld - Removing unselected file.") #define MSG_REMOVING_UNSELECTED_FILE _("GID#%" PRId64 " - Removing unselected file.")
#define MSG_FILE_REMOVED _("File %s removed.") #define MSG_FILE_REMOVED _("File %s removed.")
#define MSG_FILE_COULD_NOT_REMOVED _("File %s could not be removed.") #define MSG_FILE_COULD_NOT_REMOVED _("File %s could not be removed.")
@ -210,14 +210,14 @@
#define EX_CONNECTION_FAILED _("Connection failed.") #define EX_CONNECTION_FAILED _("Connection failed.")
#define EX_FILENAME_MISMATCH _("The requested filename and the previously registered one are not same. Expected:%s Actual:%s") #define EX_FILENAME_MISMATCH _("The requested filename and the previously registered one are not same. Expected:%s Actual:%s")
#define EX_BAD_STATUS _("The response status is not successful. status=%d") #define EX_BAD_STATUS _("The response status is not successful. status=%d")
#define EX_TOO_LARGE_FILE "Too large file size. size=%lld" #define EX_TOO_LARGE_FILE "Too large file size. size=%" PRId64 ""
#define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.") #define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.")
#define EX_SSL_INIT_FAILURE _("SSL initialization failed: %s") #define EX_SSL_INIT_FAILURE _("SSL initialization failed: %s")
#define EX_SSL_IO_ERROR _("SSL I/O error") #define EX_SSL_IO_ERROR _("SSL I/O error")
#define EX_SSL_PROTOCOL_ERROR _("SSL protocol error") #define EX_SSL_PROTOCOL_ERROR _("SSL protocol error")
#define EX_SSL_UNKNOWN_ERROR _("SSL unknown error %d") #define EX_SSL_UNKNOWN_ERROR _("SSL unknown error %d")
#define EX_SSL_CONNECT_ERROR _("SSL initialization failed: OpenSSL connect error %d") #define EX_SSL_CONNECT_ERROR _("SSL initialization failed: OpenSSL connect error %d")
#define EX_SIZE_MISMATCH "Size mismatch Expected:%lld Actual:%lld" #define EX_SIZE_MISMATCH "Size mismatch Expected:%" PRId64 " Actual:%" PRId64 ""
#define EX_AUTH_FAILED _("Authorization failed.") #define EX_AUTH_FAILED _("Authorization failed.")
#define EX_GOT_EOF _("Got EOF from the server.") #define EX_GOT_EOF _("Got EOF from the server.")
#define EX_EOF_FROM_PEER _("Got EOF from peer.") #define EX_EOF_FROM_PEER _("Got EOF from peer.")
@ -229,7 +229,7 @@
#define EX_DATA_READ _("Failed to read data from disk.") #define EX_DATA_READ _("Failed to read data from disk.")
#define EX_FILE_SHA1SUM _("Failed to calculate SHA1 digest of or a part of the file %s, cause: %s") #define EX_FILE_SHA1SUM _("Failed to calculate SHA1 digest of or a part of the file %s, cause: %s")
#define EX_FILE_SEEK _("Failed to seek the file %s, cause: %s") #define EX_FILE_SEEK _("Failed to seek the file %s, cause: %s")
#define EX_FILE_OFFSET_OUT_OF_RANGE "The offset is out of range, offset=%lld" #define EX_FILE_OFFSET_OUT_OF_RANGE "The offset is out of range, offset=%" PRId64 ""
#define EX_NOT_DIRECTORY _("%s is not a directory.") #define EX_NOT_DIRECTORY _("%s is not a directory.")
#define EX_MAKE_DIR _("Failed to make the directory %s, cause: %s") #define EX_MAKE_DIR _("Failed to make the directory %s, cause: %s")
#define EX_SEGMENT_FILE_WRITE "Failed to write into the segment file %s" #define EX_SEGMENT_FILE_WRITE "Failed to write into the segment file %s"
@ -256,7 +256,7 @@
#define EX_INVALID_PAYLOAD_SIZE \ #define EX_INVALID_PAYLOAD_SIZE \
_("Invalid payload size for %s, size=%lu. It should be %lu.") _("Invalid payload size for %s, size=%lu. It should be %lu.")
#define EX_INVALID_BT_MESSAGE_ID _("Invalid ID=%d for %s. It should be %d.") #define EX_INVALID_BT_MESSAGE_ID _("Invalid ID=%d for %s. It should be %d.")
#define EX_INVALID_CHUNK_CHECKSUM "Chunk checksum validation failed. checksumIndex=%lu, offset=%lld, expectedHash=%s, actualHash=%s" #define EX_INVALID_CHUNK_CHECKSUM "Chunk checksum validation failed. checksumIndex=%lu, offset=%" PRId64 ", expectedHash=%s, actualHash=%s"
#define EX_DOWNLOAD_ABORTED _("Download aborted.") #define EX_DOWNLOAD_ABORTED _("Download aborted.")
#define EX_DUPLICATE_FILE_DOWNLOAD _("File %s is being downloaded by other command.") #define EX_DUPLICATE_FILE_DOWNLOAD _("File %s is being downloaded by other command.")
#define EX_INSUFFICIENT_CHECKSUM _("Insufficient checksums.") #define EX_INSUFFICIENT_CHECKSUM _("Insufficient checksums.")
@ -270,7 +270,7 @@
#define EX_TOO_SLOW_DOWNLOAD_SPEED _("Too slow Downloading speed: %d <= %d(B/s), host:%s") #define EX_TOO_SLOW_DOWNLOAD_SPEED _("Too slow Downloading speed: %d <= %d(B/s), host:%s")
#define EX_NO_HTTP_REQUEST_ENTRY_FOUND _("No HttpRequestEntry found.") #define EX_NO_HTTP_REQUEST_ENTRY_FOUND _("No HttpRequestEntry found.")
#define EX_LOCATION_HEADER_REQUIRED _("Got %d status, but no location header provided.") #define EX_LOCATION_HEADER_REQUIRED _("Got %d status, but no location header provided.")
#define EX_INVALID_RANGE_HEADER "Invalid range header. Request: %lld-%lld/%lld, Response: %lld-%lld/%lld" #define EX_INVALID_RANGE_HEADER "Invalid range header. Request: %" PRId64 "-%" PRId64 "/%" PRId64 ", Response: %" PRId64 "-%" PRId64 "/%" PRId64 ""
#define EX_NO_RESULT_WITH_YOUR_PREFS _("No file matched with your preference.") #define EX_NO_RESULT_WITH_YOUR_PREFS _("No file matched with your preference.")
#define EX_EXCEPTION_CAUGHT _("Exception caught") #define EX_EXCEPTION_CAUGHT _("Exception caught")
#define EX_TOO_LONG_PAYLOAD _("Max payload length exceeded or invalid. length = %u") #define EX_TOO_LONG_PAYLOAD _("Max payload length exceeded or invalid. length = %u")

View file

@ -537,7 +537,7 @@ std::string secfmt(time_t sec) {
time_t tsec = sec; time_t tsec = sec;
std::string str; std::string str;
if(sec >= 3600) { if(sec >= 3600) {
str = fmt("%lldh", static_cast<long long int>(sec/3600)); str = fmt("%" PRId64 "h", static_cast<int64_t>(sec/3600));
sec %= 3600; sec %= 3600;
} }
if(sec >= 60) { if(sec >= 60) {