mirror of https://github.com/aria2/aria2
2009-10-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Moved static functions in Util class to namespace util. * src * testpull/1/head
parent
3349fe0811
commit
c6035b2e24
|
@ -1,3 +1,9 @@
|
|||
2009-10-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Moved static functions in Util class to namespace util.
|
||||
* src
|
||||
* test
|
||||
|
||||
2009-10-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Moved generateRandomData to Util.cc Moved flipBit to bitfield.cc.
|
||||
|
|
|
@ -403,10 +403,10 @@ public:
|
|||
|
||||
bool operator()(const std::string& domain) const
|
||||
{
|
||||
if(Util::startsWith(domain, ".")) {
|
||||
return Util::endsWith(_hostname, domain);
|
||||
if(util::startsWith(domain, ".")) {
|
||||
return util::endsWith(_hostname, domain);
|
||||
} else {
|
||||
return Util::endsWith(_hostname, "."+domain);
|
||||
return util::endsWith(_hostname, "."+domain);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -415,7 +415,7 @@ static bool inNoProxy(const SharedHandle<Request>& req,
|
|||
const std::string& noProxy)
|
||||
{
|
||||
std::vector<std::string> entries;
|
||||
split(noProxy, std::back_inserter(entries), ",", true);
|
||||
util::split(noProxy, std::back_inserter(entries), ",", true);
|
||||
if(entries.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ void AbstractDiskWriter::openExistingFile(uint64_t totalLength)
|
|||
void AbstractDiskWriter::createFile(int addFlags)
|
||||
{
|
||||
assert(!_filename.empty());
|
||||
Util::mkdirs(File(_filename).getDirname());
|
||||
util::mkdirs(File(_filename).getDirname());
|
||||
if((fd = open(_filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags,
|
||||
OPEN_MODE)) < 0) {
|
||||
throw DL_ABORT_EX(StringFormat(EX_FILE_OPEN,
|
||||
|
|
|
@ -73,7 +73,7 @@ void AnnounceList::reconfigure(const BDE& announceList)
|
|||
elemItr != elemList.listEnd(); ++elemItr) {
|
||||
const BDE& data = *elemItr;
|
||||
if(data.isString()) {
|
||||
urls.push_back(Util::trim(data.s()));
|
||||
urls.push_back(util::trim(data.s()));
|
||||
}
|
||||
}
|
||||
if(!urls.empty()) {
|
||||
|
|
|
@ -190,7 +190,7 @@ AuthConfigFactory::BasicCred::BasicCred
|
|||
_user(user), _password(password),
|
||||
_host(host), _path(path), _activated(activated)
|
||||
{
|
||||
if(!Util::endsWith(_path, "/")) {
|
||||
if(!util::endsWith(_path, "/")) {
|
||||
_path += "/";
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ AuthConfigFactory::findBasicCred(const std::string& host,
|
|||
std::deque<BasicCred>::iterator i =
|
||||
std::lower_bound(_basicCreds.begin(), _basicCreds.end(), bc);
|
||||
for(; i != _basicCreds.end() && (*i)._host == host; ++i) {
|
||||
if(Util::startsWith(bc._path, (*i)._path)) {
|
||||
if(util::startsWith(bc._path, (*i)._path)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ size_t BtBitfieldMessage::getMessageLength() {
|
|||
}
|
||||
|
||||
std::string BtBitfieldMessage::toString() const {
|
||||
return strconcat(NAME, " ", Util::toHex(bitfield, bitfieldLength));
|
||||
return strconcat(NAME, " ", util::toHex(bitfield, bitfieldLength));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -70,7 +70,7 @@ bool BtDependency::resolve()
|
|||
DiskAdaptorHandle diskAdaptor =
|
||||
dependee->getPieceStorage()->getDiskAdaptor();
|
||||
diskAdaptor->openExistingFile();
|
||||
std::string content = Util::toString(diskAdaptor);
|
||||
std::string content = util::toString(diskAdaptor);
|
||||
bittorrent::loadFromMemory
|
||||
(content, context, File(dependee->getFirstFilePath()).getBasename());
|
||||
if(context->getFileEntries().size() !=
|
||||
|
|
|
@ -106,9 +106,9 @@ size_t BtHandshakeMessage::getMessageLength() {
|
|||
|
||||
std::string BtHandshakeMessage::toString() const {
|
||||
return strconcat(NAME, " peerId=",
|
||||
Util::urlencode(peerId, PEER_ID_LENGTH),
|
||||
util::urlencode(peerId, PEER_ID_LENGTH),
|
||||
", reserved=",
|
||||
Util::toHex(reserved, RESERVED_LENGTH));
|
||||
util::toHex(reserved, RESERVED_LENGTH));
|
||||
}
|
||||
|
||||
bool BtHandshakeMessage::isFastExtensionSupported() const {
|
||||
|
|
|
@ -66,13 +66,13 @@ 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::urlencode(message->getPstr(), 19).c_str()).str());
|
||||
}
|
||||
if(memcmp(infoHash, message->getInfoHash(), 20) != 0) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("invalid handshake info hash: expected:%s, actual:%s",
|
||||
Util::toHex(infoHash, 20).c_str(),
|
||||
Util::toHex(message->getInfoHash(), 20).c_str()).str());
|
||||
util::toHex(infoHash, 20).c_str(),
|
||||
util::toHex(message->getInfoHash(), 20).c_str()).str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ void BtPieceMessage::doReceivedAction() {
|
|||
pieceStorage->getDiskAdaptor()->writeData(block, blockLength, offset);
|
||||
piece->completeBlock(slot.getBlockIndex());
|
||||
logger->debug(MSG_PIECE_BITFIELD, cuid,
|
||||
Util::toHex(piece->getBitfield(),
|
||||
util::toHex(piece->getBitfield(),
|
||||
piece->getBitfieldLength()).c_str());
|
||||
piece->updateHash(begin, block, blockLength);
|
||||
dispatcher->removeOutstandingRequest(slot);
|
||||
|
@ -168,8 +168,8 @@ size_t BtPieceMessage::sendPieceData(off_t offset, size_t length) const {
|
|||
}
|
||||
|
||||
std::string BtPieceMessage::toString() const {
|
||||
return strconcat(NAME, " index=", Util::itos(index), ", begin=",
|
||||
Util::itos(begin), ", length=", Util::itos(blockLength));
|
||||
return strconcat(NAME, " index=", util::itos(index), ", begin=",
|
||||
util::itos(begin), ", length=", util::itos(blockLength));
|
||||
}
|
||||
|
||||
bool BtPieceMessage::checkPieceHash(const PieceHandle& piece) {
|
||||
|
|
|
@ -110,7 +110,7 @@ size_t BtPortMessage::getMessageLength() {
|
|||
}
|
||||
|
||||
std::string BtPortMessage::toString() const {
|
||||
return strconcat(NAME, " port=", Util::uitos(_port));
|
||||
return strconcat(NAME, " port=", util::uitos(_port));
|
||||
}
|
||||
|
||||
void BtPortMessage::setLocalNode(const WeakHandle<DHTNode>& localNode)
|
||||
|
|
|
@ -74,7 +74,7 @@ void BtPostDownloadHandler::getNextRequestGroups
|
|||
std::string content;
|
||||
try {
|
||||
requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile();
|
||||
content = Util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
||||
content = util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
||||
requestGroup->getPieceStorage()->getDiskAdaptor()->closeFile();
|
||||
} catch(Exception& e) {
|
||||
requestGroup->getPieceStorage()->getDiskAdaptor()->closeFile();
|
||||
|
|
|
@ -149,7 +149,7 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
|||
|
||||
if(PeerListenCommand::getNumInstance() == 0) {
|
||||
PeerListenCommand* listenCommand = PeerListenCommand::getInstance(e);
|
||||
IntSequence seq = Util::parseIntRange(option->get(PREF_LISTEN_PORT));
|
||||
IntSequence seq = util::parseIntRange(option->get(PREF_LISTEN_PORT));
|
||||
uint16_t port;
|
||||
if(listenCommand->bindPort(port, seq)) {
|
||||
btRuntime->setListenPort(port);
|
||||
|
|
|
@ -59,7 +59,7 @@ static bool readChunkSize(uint64_t& chunkSize, std::string& in)
|
|||
if(extPos == std::string::npos || crlfPos < extPos) {
|
||||
extPos = crlfPos;
|
||||
}
|
||||
chunkSize = Util::parseULLInt(in.substr(0, extPos), 16);
|
||||
chunkSize = util::parseULLInt(in.substr(0, extPos), 16);
|
||||
in.erase(0, crlfPos+2);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -98,10 +98,10 @@ static void printProgress
|
|||
#endif // ENABLE_BITTORRENT
|
||||
{
|
||||
o << "SIZE:"
|
||||
<< Util::abbrevSize(rg->getCompletedLength())
|
||||
<< util::abbrevSize(rg->getCompletedLength())
|
||||
<< "B"
|
||||
<< "/"
|
||||
<< Util::abbrevSize(rg->getTotalLength())
|
||||
<< util::abbrevSize(rg->getTotalLength())
|
||||
<< "B";
|
||||
if(rg->getTotalLength() > 0) {
|
||||
o << "("
|
||||
|
@ -128,18 +128,18 @@ static void printProgress
|
|||
if(!rg->downloadFinished()) {
|
||||
o << " "
|
||||
<< "SPD:"
|
||||
<< Util::abbrevSize(stat.getDownloadSpeed()) << "Bs";
|
||||
<< util::abbrevSize(stat.getDownloadSpeed()) << "Bs";
|
||||
}
|
||||
if(stat.getSessionUploadLength() > 0) {
|
||||
o << " "
|
||||
<< "UP:"
|
||||
<< Util::abbrevSize(stat.getUploadSpeed()) << "Bs"
|
||||
<< "(" << Util::abbrevSize(stat.getAllTimeUploadLength()) << "B)";
|
||||
<< util::abbrevSize(stat.getUploadSpeed()) << "Bs"
|
||||
<< "(" << util::abbrevSize(stat.getAllTimeUploadLength()) << "B)";
|
||||
}
|
||||
if(eta > 0) {
|
||||
o << " "
|
||||
<< "ETA:"
|
||||
<< Util::secfmt(eta);
|
||||
<< util::secfmt(eta);
|
||||
}
|
||||
o << "]";
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
|||
TransferStat stat = e->_requestGroupMan->calculateStat();
|
||||
o << " "
|
||||
<< "[TOTAL SPD:"
|
||||
<< Util::abbrevSize(stat.getDownloadSpeed()) << "Bs" << "]";
|
||||
<< util::abbrevSize(stat.getDownloadSpeed()) << "Bs" << "]";
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -250,10 +250,10 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
|||
o << " "
|
||||
<< "[FileAlloc:"
|
||||
<< "#" << entry->getRequestGroup()->getGID() << " "
|
||||
<< Util::abbrevSize(entry->getCurrentLength())
|
||||
<< util::abbrevSize(entry->getCurrentLength())
|
||||
<< "B"
|
||||
<< "/"
|
||||
<< Util::abbrevSize(entry->getTotalLength())
|
||||
<< util::abbrevSize(entry->getTotalLength())
|
||||
<< "B"
|
||||
<< "(";
|
||||
if(entry->getTotalLength() > 0) {
|
||||
|
@ -277,10 +277,10 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
|||
o << " "
|
||||
<< "[Checksum:"
|
||||
<< "#" << entry->getRequestGroup()->getGID() << " "
|
||||
<< Util::abbrevSize(entry->getCurrentLength())
|
||||
<< util::abbrevSize(entry->getCurrentLength())
|
||||
<< "B"
|
||||
<< "/"
|
||||
<< Util::abbrevSize(entry->getTotalLength())
|
||||
<< util::abbrevSize(entry->getTotalLength())
|
||||
<< "B"
|
||||
<< "("
|
||||
<< 100*entry->getCurrentLength()/entry->getTotalLength()
|
||||
|
|
|
@ -48,7 +48,7 @@ bool tailMatch
|
|||
(InputIterator first, InputIterator last, const std::string& target)
|
||||
{
|
||||
for(; first != last; ++first) {
|
||||
if(Util::endsWith(target, *first)) {
|
||||
if(util::endsWith(target, *first)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,16 +56,16 @@ static std::string prependDotIfNotExists(const std::string& domain)
|
|||
|
||||
static std::string normalizeDomain(const std::string& domain)
|
||||
{
|
||||
if(domain.empty() || Util::isNumbersAndDotsNotation(domain)) {
|
||||
if(domain.empty() || util::isNumbersAndDotsNotation(domain)) {
|
||||
return domain;
|
||||
}
|
||||
std::string md = prependDotIfNotExists(domain);
|
||||
// TODO use Util::split to strict verification
|
||||
// TODO use util::split to strict verification
|
||||
std::string::size_type p = md.find_last_of(".");
|
||||
if(p == 0 || p == std::string::npos) {
|
||||
md += ".local";
|
||||
}
|
||||
return Util::toLower(prependDotIfNotExists(md));
|
||||
return util::toLower(prependDotIfNotExists(md));
|
||||
}
|
||||
|
||||
Cookie::Cookie(const std::string& name,
|
||||
|
@ -112,12 +112,12 @@ static bool pathInclude(const std::string& requestPath, const std::string& path)
|
|||
if(requestPath == path) {
|
||||
return true;
|
||||
}
|
||||
if(Util::startsWith(requestPath, path)) {
|
||||
if(util::startsWith(requestPath, path)) {
|
||||
if(*path.rbegin() != '/' && requestPath[path.size()] != '/') {
|
||||
return false;
|
||||
}
|
||||
} else if(*path.rbegin() != '/' || *requestPath.rbegin() == '/' ||
|
||||
!Util::startsWith(requestPath+"/", path)) {
|
||||
!util::startsWith(requestPath+"/", path)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -135,7 +135,7 @@ static bool domainMatch(const std::string& normReqHost,
|
|||
// Also original Netscape implementation behaves exactly the same.
|
||||
|
||||
// _domain always starts ".". See Cookie::Cookie().
|
||||
return Util::endsWith(normReqHost, domain);
|
||||
return util::endsWith(normReqHost, domain);
|
||||
}
|
||||
|
||||
bool Cookie::match(const std::string& requestHost,
|
||||
|
@ -172,7 +172,7 @@ bool Cookie::validate(const std::string& requestHost,
|
|||
if(_domain.size() < 4 || _domain.find(".", 1) == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
if(!Util::endsWith(normReqHost, _domain)) {
|
||||
if(!util::endsWith(normReqHost, _domain)) {
|
||||
return false;
|
||||
}
|
||||
// From RFC2965 3.3.2 Rejecting Cookies
|
||||
|
@ -211,7 +211,7 @@ std::string Cookie::toNsCookieFormat() const
|
|||
{
|
||||
std::stringstream ss;
|
||||
ss << _domain << "\t";
|
||||
if(Util::startsWith(_domain, ".")) {
|
||||
if(util::startsWith(_domain, ".")) {
|
||||
ss << "TRUE";
|
||||
} else {
|
||||
ss << "FALSE";
|
||||
|
|
|
@ -63,12 +63,12 @@ Cookie CookieParser::parse(const std::string& cookieStr) const
|
|||
Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defaultDomain, const std::string& defaultPath) const
|
||||
{
|
||||
std::vector<std::string> terms;
|
||||
split(cookieStr, std::back_inserter(terms), ";", true);
|
||||
util::split(cookieStr, std::back_inserter(terms), ";", true);
|
||||
if(terms.empty()) {
|
||||
return Cookie();
|
||||
}
|
||||
std::pair<std::string, std::string> nameValue;
|
||||
Util::split(nameValue, terms.front(), '=');
|
||||
util::split(nameValue, terms.front(), '=');
|
||||
|
||||
std::map<std::string, std::string> values;
|
||||
values[C_DOMAIN] = defaultDomain;
|
||||
|
@ -77,7 +77,7 @@ Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defa
|
|||
for(std::vector<std::string>::iterator itr = terms.begin()+1;
|
||||
itr != terms.end(); ++itr) {
|
||||
std::pair<std::string, std::string> nv;
|
||||
Util::split(nv, *itr, '=');
|
||||
util::split(nv, *itr, '=');
|
||||
values[nv.first] = nv.second;
|
||||
}
|
||||
time_t expiry = 0;
|
||||
|
@ -99,7 +99,7 @@ Cookies CookieParser::parse(std::istream& s) const
|
|||
Cookies cookies;
|
||||
std::string line;
|
||||
while(getline(s, line)) {
|
||||
if(Util::trim(line).empty() || Util::startsWith(line, A2STR::SHARP_C)) {
|
||||
if(util::trim(line).empty() || util::startsWith(line, A2STR::SHARP_C)) {
|
||||
continue;
|
||||
}
|
||||
Cookie cookie = parse(line);
|
||||
|
|
|
@ -86,7 +86,7 @@ void DHTAbstractNodeLookupTask::onReceived(const SharedHandle<DHTMessage>& messa
|
|||
}
|
||||
if(_inFlightMessage == 0) {
|
||||
_logger->debug("Finished node_lookup for node ID %s",
|
||||
Util::toHex(_targetID, DHT_ID_LENGTH).c_str());
|
||||
util::toHex(_targetID, DHT_ID_LENGTH).c_str());
|
||||
onFinish();
|
||||
updateBucket();
|
||||
_finished = true;
|
||||
|
@ -96,7 +96,7 @@ void DHTAbstractNodeLookupTask::onReceived(const SharedHandle<DHTMessage>& messa
|
|||
void DHTAbstractNodeLookupTask::onTimeout(const SharedHandle<DHTNode>& node)
|
||||
{
|
||||
_logger->debug("node lookup message timeout for node ID=%s",
|
||||
Util::toHex(node->getID(), DHT_ID_LENGTH).c_str());
|
||||
util::toHex(node->getID(), DHT_ID_LENGTH).c_str());
|
||||
--_inFlightMessage;
|
||||
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i = _entries.begin(); i != _entries.end(); ++i) {
|
||||
if((*i)->_node == node) {
|
||||
|
@ -109,7 +109,7 @@ void DHTAbstractNodeLookupTask::onTimeout(const SharedHandle<DHTNode>& node)
|
|||
}
|
||||
if(_inFlightMessage == 0) {
|
||||
_logger->debug("Finished node_lookup for node ID %s",
|
||||
Util::toHex(_targetID, DHT_ID_LENGTH).c_str());
|
||||
util::toHex(_targetID, DHT_ID_LENGTH).c_str());
|
||||
onFinish();
|
||||
updateBucket();
|
||||
_finished = true;
|
||||
|
|
|
@ -107,7 +107,7 @@ void DHTAnnouncePeerMessage::validate() const
|
|||
_remoteNode->getPort())) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("Invalid token=%s from %s:%u",
|
||||
Util::toHex(_token).c_str(),
|
||||
util::toHex(_token).c_str(),
|
||||
_remoteNode->getIPAddress().c_str(),
|
||||
_remoteNode->getPort()).str());
|
||||
}
|
||||
|
@ -125,9 +125,9 @@ void DHTAnnouncePeerMessage::setTokenTracker(const WeakHandle<DHTTokenTracker>&
|
|||
|
||||
std::string DHTAnnouncePeerMessage::toStringOptional() const
|
||||
{
|
||||
return strconcat("token=", Util::toHex(_token),
|
||||
", info_hash=", Util::toHex(_infoHash, INFO_HASH_LENGTH),
|
||||
", tcpPort=", Util::uitos(_tcpPort));
|
||||
return strconcat("token=", util::toHex(_token),
|
||||
", info_hash=", util::toHex(_infoHash, INFO_HASH_LENGTH),
|
||||
", tcpPort=", util::uitos(_tcpPort));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -203,12 +203,12 @@ SharedHandle<DHTBucket> DHTBucket::split()
|
|||
// TODO create toString() and use it.
|
||||
_logger->debug("New bucket. prefixLength=%u, Range:%s-%s",
|
||||
static_cast<unsigned int>(rBucket->getPrefixLength()),
|
||||
Util::toHex(rBucket->getMinID(), DHT_ID_LENGTH).c_str(),
|
||||
Util::toHex(rBucket->getMaxID(), DHT_ID_LENGTH).c_str());
|
||||
util::toHex(rBucket->getMinID(), DHT_ID_LENGTH).c_str(),
|
||||
util::toHex(rBucket->getMaxID(), DHT_ID_LENGTH).c_str());
|
||||
_logger->debug("Existing bucket. prefixLength=%u, Range:%s-%s",
|
||||
static_cast<unsigned int>(_prefixLength),
|
||||
Util::toHex(getMinID(), DHT_ID_LENGTH).c_str(),
|
||||
Util::toHex(getMaxID(), DHT_ID_LENGTH).c_str());
|
||||
util::toHex(getMinID(), DHT_ID_LENGTH).c_str(),
|
||||
util::toHex(getMaxID(), DHT_ID_LENGTH).c_str());
|
||||
|
||||
return rBucket;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ void DHTBucketRefreshTask::startup()
|
|||
task->setTaskQueue(_taskQueue);
|
||||
task->setLocalNode(_localNode);
|
||||
|
||||
_logger->info("Dispating bucket refresh. targetID=%s", Util::toHex(targetID, DHT_ID_LENGTH).c_str());
|
||||
_logger->info("Dispating bucket refresh. targetID=%s", util::toHex(targetID, DHT_ID_LENGTH).c_str());
|
||||
_taskQueue->addPeriodicTask1(task);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ void DHTFindNodeMessage::validate() const {}
|
|||
|
||||
std::string DHTFindNodeMessage::toStringOptional() const
|
||||
{
|
||||
return "targetNodeID="+Util::toHex(_targetNodeID, DHT_ID_LENGTH);
|
||||
return "targetNodeID="+util::toHex(_targetNodeID, DHT_ID_LENGTH);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -103,7 +103,7 @@ void DHTFindNodeReplyMessage::setClosestKNodes(const std::deque<SharedHandle<DHT
|
|||
|
||||
std::string DHTFindNodeReplyMessage::toStringOptional() const
|
||||
{
|
||||
return "nodes="+Util::uitos(_closestKNodes.size());
|
||||
return "nodes="+util::uitos(_closestKNodes.size());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -114,7 +114,7 @@ void DHTGetPeersMessage::setTokenTracker(const WeakHandle<DHTTokenTracker>& toke
|
|||
|
||||
std::string DHTGetPeersMessage::toStringOptional() const
|
||||
{
|
||||
return "info_hash="+Util::toHex(_infoHash, INFO_HASH_LENGTH);
|
||||
return "info_hash="+util::toHex(_infoHash, INFO_HASH_LENGTH);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -137,9 +137,9 @@ void DHTGetPeersReplyMessage::setValues(const std::deque<SharedHandle<Peer> >& p
|
|||
|
||||
std::string DHTGetPeersReplyMessage::toStringOptional() const
|
||||
{
|
||||
return strconcat("token=", Util::toHex(_token),
|
||||
", values=", Util::uitos(_values.size()),
|
||||
", nodes=", Util::uitos(_closestKNodes.size()));
|
||||
return strconcat("token=", util::toHex(_token),
|
||||
", values=", util::uitos(_values.size()),
|
||||
", nodes=", util::uitos(_closestKNodes.size()));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -170,7 +170,7 @@ void DHTMessageFactoryImpl::validatePort(const BDE& i) const
|
|||
if(!(0 < port && port < UINT16_MAX)) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("Malformed DHT message. Invalid port=%s",
|
||||
Util::itos(port).c_str()).str());
|
||||
util::itos(port).c_str()).str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,8 +233,8 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
|
|||
const BDE& e = getList(dict, DHTUnknownMessage::E);
|
||||
if(e.size() == 2) {
|
||||
_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::itos(getInteger(e, 0).i()).c_str(),
|
||||
util::urlencode(getString(e, 1).s()).c_str());
|
||||
} else {
|
||||
_logger->debug("e doesn't have 2 elements.");
|
||||
}
|
||||
|
@ -242,7 +242,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::urlencode(y.s()).c_str()).str());
|
||||
}
|
||||
const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
|
||||
const BDE& id = getString(rDict, DHTMessage::ID);
|
||||
|
|
|
@ -78,7 +78,7 @@ DHTMessageTracker::messageArrived(const BDE& dict,
|
|||
ipaddr.c_str(), port).str());
|
||||
}
|
||||
_logger->debug("Searching tracker entry for TransactionID=%s, Remote=%s:%u",
|
||||
Util::toHex(tid.s()).c_str(), ipaddr.c_str(), port);
|
||||
util::toHex(tid.s()).c_str(), ipaddr.c_str(), port);
|
||||
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i =
|
||||
_entries.begin(); i != _entries.end(); ++i) {
|
||||
if((*i)->match(tid.s(), ipaddr, port)) {
|
||||
|
@ -93,7 +93,7 @@ DHTMessageTracker::messageArrived(const BDE& dict,
|
|||
targetNode->getPort());
|
||||
|
||||
int64_t rtt = entry->getElapsedMillis();
|
||||
_logger->debug("RTT is %s", Util::itos(rtt).c_str());
|
||||
_logger->debug("RTT is %s", util::itos(rtt).c_str());
|
||||
message->getRemoteNode()->updateRTT(rtt);
|
||||
SharedHandle<DHTMessageCallback> callback = entry->getCallback();
|
||||
return std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> >(message, callback);
|
||||
|
|
|
@ -67,9 +67,9 @@ bool DHTMessageTrackerEntry::match(const std::string& transactionID, const std::
|
|||
if(_targetNode->getIPAddress() == ipaddr) {
|
||||
return true;
|
||||
}
|
||||
if(Util::endsWith(_targetNode->getIPAddress(), ipaddr)) {
|
||||
if(util::endsWith(_targetNode->getIPAddress(), ipaddr)) {
|
||||
return _targetNode->getIPAddress() == "::ffff:"+ipaddr;
|
||||
} else if(Util::endsWith(ipaddr, _targetNode->getIPAddress())) {
|
||||
} else if(util::endsWith(ipaddr, _targetNode->getIPAddress())) {
|
||||
return ipaddr == "::ffff:"+_targetNode->getIPAddress();
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -113,10 +113,10 @@ void DHTNode::timeout()
|
|||
|
||||
std::string DHTNode::toString() const
|
||||
{
|
||||
return strconcat("DHTNode ID=", Util::toHex(_id, DHT_ID_LENGTH),
|
||||
", Host=", _ipaddr, ":", Util::uitos(_port),
|
||||
", Condition=", Util::uitos(_condition),
|
||||
", RTT=", Util::uitos(_rtt));
|
||||
return strconcat("DHTNode ID=", util::toHex(_id, DHT_ID_LENGTH),
|
||||
", Host=", _ipaddr, ":", util::uitos(_port),
|
||||
", Condition=", util::uitos(_condition),
|
||||
", RTT=", util::uitos(_rtt));
|
||||
}
|
||||
|
||||
void DHTNode::setID(const unsigned char* id)
|
||||
|
|
|
@ -88,7 +88,7 @@ DHTPeerAnnounceStorage::addPeerAnnounce(const unsigned char* infoHash,
|
|||
const std::string& ipaddr, uint16_t port)
|
||||
{
|
||||
_logger->debug("Adding %s:%u to peer announce list: infoHash=%s",
|
||||
ipaddr.c_str(), port, Util::toHex(infoHash, DHT_ID_LENGTH).c_str());
|
||||
ipaddr.c_str(), port, util::toHex(infoHash, DHT_ID_LENGTH).c_str());
|
||||
getPeerAnnounceEntry(infoHash)->addPeerAddrEntry(PeerAddrEntry(ipaddr, port));
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ void DHTPeerAnnounceStorage::addPeerAnnounce
|
|||
(const unsigned char* infoHash, const SharedHandle<PeerStorage>& peerStorage)
|
||||
{
|
||||
_logger->debug("Adding localhost to peer announce list: infoHash=%s",
|
||||
Util::toHex(infoHash, DHT_ID_LENGTH).c_str());
|
||||
util::toHex(infoHash, DHT_ID_LENGTH).c_str());
|
||||
SharedHandle<DHTPeerAnnounceEntry> entry =
|
||||
getPeerAnnounceEntry(infoHash);
|
||||
entry->setPeerStorage(peerStorage);
|
||||
|
@ -172,7 +172,7 @@ void DHTPeerAnnounceStorage::announcePeer()
|
|||
SharedHandle<DHTTask> task = _taskFactory->createPeerAnnounceTask((*i)->getInfoHash());
|
||||
_taskQueue->addPeriodicTask2(task);
|
||||
_logger->debug("Added 1 peer announce: infoHash=%s",
|
||||
Util::toHex((*i)->getInfoHash(), DHT_ID_LENGTH).c_str());
|
||||
util::toHex((*i)->getInfoHash(), DHT_ID_LENGTH).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ void DHTPeerLookupTask::onReceivedInternal(const SharedHandle<DHTMessage>& messa
|
|||
return;
|
||||
}
|
||||
SharedHandle<DHTNode> remoteNode = m->getRemoteNode();
|
||||
_tokenStorage[Util::toHex(remoteNode->getID(), DHT_ID_LENGTH)] = m->getToken();
|
||||
_tokenStorage[util::toHex(remoteNode->getID(), DHT_ID_LENGTH)] = m->getToken();
|
||||
|
||||
_peerStorage->addPeer(m->getValues());
|
||||
_peers.insert(_peers.end(), m->getValues().begin(), m->getValues().end());
|
||||
|
@ -96,7 +96,7 @@ void DHTPeerLookupTask::onFinish()
|
|||
(node,
|
||||
_targetID, // this is infoHash
|
||||
_btRuntime->getListenPort(),
|
||||
_tokenStorage[Util::toHex(node->getID(), DHT_ID_LENGTH)]);
|
||||
_tokenStorage[util::toHex(node->getID(), DHT_ID_LENGTH)]);
|
||||
_dispatcher->addMessageToQueue(m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,10 +70,10 @@ bool DHTQueryMessage::isReply() const
|
|||
std::string DHTQueryMessage::toString() const
|
||||
{
|
||||
return strconcat("dht query ", getMessageType(),
|
||||
" TransactionID=", Util::toHex(_transactionID),
|
||||
" TransactionID=", util::toHex(_transactionID),
|
||||
" Remote:", _remoteNode->getIPAddress(),
|
||||
":", Util::uitos(_remoteNode->getPort()),
|
||||
", id=", Util::toHex(_remoteNode->getID(), DHT_ID_LENGTH),
|
||||
":", util::uitos(_remoteNode->getPort()),
|
||||
", id=", util::toHex(_remoteNode->getID(), DHT_ID_LENGTH),
|
||||
", ", toStringOptional());
|
||||
}
|
||||
|
||||
|
|
|
@ -67,10 +67,10 @@ bool DHTResponseMessage::isReply() const
|
|||
std::string DHTResponseMessage::toString() const
|
||||
{
|
||||
return strconcat("dht response ", getMessageType(),
|
||||
" TransactionID=", Util::toHex(_transactionID),
|
||||
" TransactionID=", util::toHex(_transactionID),
|
||||
" Remote:", _remoteNode->getIPAddress(),
|
||||
":", Util::uitos(_remoteNode->getPort()),
|
||||
", id=", Util::toHex(_remoteNode->getID(), DHT_ID_LENGTH),
|
||||
":", util::uitos(_remoteNode->getPort()),
|
||||
", id=", util::toHex(_remoteNode->getID(), DHT_ID_LENGTH),
|
||||
", ", toStringOptional());
|
||||
}
|
||||
|
||||
|
|
|
@ -88,8 +88,8 @@ bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
|
|||
return true;
|
||||
} else if(bucket->splitAllowed()) {
|
||||
_logger->debug("Splitting bucket. Range:%s-%s",
|
||||
Util::toHex(bucket->getMinID(), DHT_ID_LENGTH).c_str(),
|
||||
Util::toHex(bucket->getMaxID(), DHT_ID_LENGTH).c_str());
|
||||
util::toHex(bucket->getMinID(), DHT_ID_LENGTH).c_str(),
|
||||
util::toHex(bucket->getMaxID(), DHT_ID_LENGTH).c_str());
|
||||
SharedHandle<DHTBucket> r = bucket->split();
|
||||
|
||||
bnode->setBucket(SharedHandle<DHTBucket>());
|
||||
|
|
|
@ -111,7 +111,7 @@ void DHTSetup::setup(std::deque<Command*>& commands,
|
|||
|
||||
SharedHandle<DHTConnectionImpl> connection(new DHTConnectionImpl());
|
||||
{
|
||||
IntSequence seq = Util::parseIntRange(option->get(PREF_DHT_LISTEN_PORT));
|
||||
IntSequence seq = util::parseIntRange(option->get(PREF_DHT_LISTEN_PORT));
|
||||
uint16_t port;
|
||||
if(!connection->bind(port, seq)) {
|
||||
throw DL_ABORT_EX("Error occurred while binding port for DHT");
|
||||
|
@ -119,7 +119,7 @@ void DHTSetup::setup(std::deque<Command*>& commands,
|
|||
localNode->setPort(port);
|
||||
}
|
||||
_logger->debug("Initialized local node ID=%s",
|
||||
Util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str());
|
||||
util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str());
|
||||
|
||||
SharedHandle<DHTRoutingTable> routingTable(new DHTRoutingTable(localNode));
|
||||
|
||||
|
|
|
@ -92,9 +92,9 @@ std::string DHTUnknownMessage::toString() const
|
|||
}
|
||||
std::string sample(&_data[0], &_data[sampleLength]);
|
||||
|
||||
return strconcat("dht unknown Remote:", _ipaddr, ":", Util::uitos(_port),
|
||||
" length=", Util::uitos(_length),
|
||||
", first 8 bytes(hex)=", Util::toHex(sample));
|
||||
return strconcat("dht unknown Remote:", _ipaddr, ":", util::uitos(_port),
|
||||
" length=", util::uitos(_length),
|
||||
", first 8 bytes(hex)=", util::toHex(sample));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -79,7 +79,7 @@ DefaultBtAnnounce::~DefaultBtAnnounce() {
|
|||
|
||||
void DefaultBtAnnounce::generateKey()
|
||||
{
|
||||
key = Util::randomAlpha(8, _randomizer);
|
||||
key = util::randomAlpha(8, _randomizer);
|
||||
}
|
||||
|
||||
bool DefaultBtAnnounce::isDefaultAnnounceReady() {
|
||||
|
@ -147,25 +147,25 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
|||
std::string url = announceList.getAnnounce();
|
||||
url += uriHasQuery(url) ? "&" : "?";
|
||||
url += "info_hash=";
|
||||
url += Util::torrentUrlencode(bittorrent::getInfoHash(_downloadContext),
|
||||
url += util::torrentUrlencode(bittorrent::getInfoHash(_downloadContext),
|
||||
INFO_HASH_LENGTH);
|
||||
url += "&peer_id=";
|
||||
url += Util::torrentUrlencode(bittorrent::getStaticPeerId(), PEER_ID_LENGTH);
|
||||
url += util::torrentUrlencode(bittorrent::getStaticPeerId(), PEER_ID_LENGTH);
|
||||
url += "&uploaded=";
|
||||
url += Util::uitos(stat.getSessionUploadLength());
|
||||
url += util::uitos(stat.getSessionUploadLength());
|
||||
url += "&downloaded=";
|
||||
url += Util::uitos(stat.getSessionDownloadLength());
|
||||
url += util::uitos(stat.getSessionDownloadLength());
|
||||
url += "&left=";
|
||||
url += Util::uitos(left);
|
||||
url += util::uitos(left);
|
||||
url += "&compact=1";
|
||||
url += "&key=";
|
||||
url += key;
|
||||
url += "&numwant=";
|
||||
url += Util::uitos(numWant);
|
||||
url += util::uitos(numWant);
|
||||
url += "&no_peer_id=1";
|
||||
if(btRuntime->getListenPort() > 0) {
|
||||
url += "&port=";
|
||||
url += Util::uitos(btRuntime->getListenPort());
|
||||
url += util::uitos(btRuntime->getListenPort());
|
||||
}
|
||||
std::string event = announceList.getEventString();
|
||||
if(!event.empty()) {
|
||||
|
@ -173,7 +173,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
|||
url += event;
|
||||
}
|
||||
if(!trackerId.empty()) {
|
||||
url += "&trackerid="+Util::torrentUrlencode(trackerId);
|
||||
url += "&trackerid="+util::torrentUrlencode(trackerId);
|
||||
}
|
||||
if(option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
|
||||
url += "&requirecrypto=1";
|
||||
|
|
|
@ -230,7 +230,7 @@ void DefaultBtProgressInfoFile::load()
|
|||
unsigned char versionBuf[2];
|
||||
in.read((char*)versionBuf, sizeof(versionBuf));
|
||||
CHECK_STREAM(in, sizeof(versionBuf));
|
||||
std::string versionHex = Util::toHex(versionBuf, sizeof(versionBuf));
|
||||
std::string versionHex = util::toHex(versionBuf, sizeof(versionBuf));
|
||||
int version;
|
||||
if(DefaultBtProgressInfoFile::V0000 == versionHex) {
|
||||
version = 0;
|
||||
|
@ -273,8 +273,8 @@ void DefaultBtProgressInfoFile::load()
|
|||
memcmp(savedInfoHash, infoHash, INFO_HASH_LENGTH) != 0) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("info hash mismatch. expected: %s, actual: %s",
|
||||
Util::toHex(infoHash, INFO_HASH_LENGTH).c_str(),
|
||||
Util::toHex(savedInfoHash, infoHashLength).c_str()
|
||||
util::toHex(infoHash, INFO_HASH_LENGTH).c_str(),
|
||||
util::toHex(savedInfoHash, infoHashLength).c_str()
|
||||
).str());
|
||||
}
|
||||
}
|
||||
|
@ -297,8 +297,8 @@ void DefaultBtProgressInfoFile::load()
|
|||
if(totalLength != _dctx->getTotalLength()) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("total length mismatch. expected: %s, actual: %s",
|
||||
Util::itos(_dctx->getTotalLength()).c_str(),
|
||||
Util::itos(totalLength).c_str()).str());
|
||||
util::itos(_dctx->getTotalLength()).c_str(),
|
||||
util::itos(totalLength).c_str()).str());
|
||||
}
|
||||
uint64_t uploadLength;
|
||||
in.read(reinterpret_cast<char*>(&uploadLength), sizeof(uploadLength));
|
||||
|
@ -411,7 +411,7 @@ void DefaultBtProgressInfoFile::load()
|
|||
" progress.");
|
||||
}
|
||||
BitfieldMan dest(_dctx->getPieceLength(), totalLength);
|
||||
Util::convertBitfield(&dest, &src);
|
||||
util::convertBitfield(&dest, &src);
|
||||
_pieceStorage->setBitfield(dest.getBitfield(), dest.getBitfieldLength());
|
||||
}
|
||||
_logger->info(MSG_LOADED_SEGMENT_FILE);
|
||||
|
|
|
@ -320,7 +320,7 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
|
|||
} else {
|
||||
logger->info(EX_INVALID_CHUNK_CHECKSUM,
|
||||
segment->getIndex(),
|
||||
Util::itos(segment->getPosition(), true).c_str(),
|
||||
util::itos(segment->getPosition(), true).c_str(),
|
||||
expectedPieceHash.c_str(),
|
||||
actualPieceHash.c_str());
|
||||
segment->clear();
|
||||
|
|
|
@ -274,7 +274,7 @@ void DownloadEngine::poolSocket(const std::string& ipaddr,
|
|||
uint16_t port,
|
||||
const SocketPoolEntry& entry)
|
||||
{
|
||||
std::string addr = strconcat(ipaddr, ":", Util::uitos(port));
|
||||
std::string addr = strconcat(ipaddr, ":", util::uitos(port));
|
||||
logger->info("Pool socket for %s", addr.c_str());
|
||||
std::multimap<std::string, SocketPoolEntry>::value_type p(addr, entry);
|
||||
_socketPool.insert(p);
|
||||
|
@ -353,7 +353,7 @@ std::multimap<std::string, DownloadEngine::SocketPoolEntry>::iterator
|
|||
DownloadEngine::findSocketPoolEntry(const std::string& ipaddr, uint16_t port)
|
||||
{
|
||||
std::string addr = ipaddr;
|
||||
strappend(addr, ":", Util::uitos(port));
|
||||
strappend(addr, ":", util::uitos(port));
|
||||
std::pair<std::multimap<std::string, SocketPoolEntry>::iterator,
|
||||
std::multimap<std::string, SocketPoolEntry>::iterator> range =
|
||||
_socketPool.equal_range(addr);
|
||||
|
|
|
@ -64,7 +64,7 @@ static void mlStartElement(void* userData, const char* name, const char** attrs)
|
|||
if(*p == 0) {
|
||||
break;
|
||||
}
|
||||
std::string value = Util::trim(*p++);
|
||||
std::string value = util::trim(*p++);
|
||||
attrmap[name] = value;
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ static void mlEndElement(void* userData, const char* name)
|
|||
SessionData* sd = reinterpret_cast<SessionData*>(userData);
|
||||
std::string characters;
|
||||
if(sd->_stm->needsCharactersBuffering()) {
|
||||
characters = Util::trim(sd->_charactersStack.front());
|
||||
characters = util::trim(sd->_charactersStack.front());
|
||||
sd->_charactersStack.pop_front();
|
||||
}
|
||||
sd->_stm->endElement(name, characters);
|
||||
|
|
|
@ -67,7 +67,7 @@ static void mlStartElement(void* userData, const char* name, const char** attrs)
|
|||
if(*p == 0) {
|
||||
break;
|
||||
}
|
||||
std::string value = Util::trim(*p++);
|
||||
std::string value = util::trim(*p++);
|
||||
attrmap[name] = value;
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ static void mlEndElement(void* userData, const char* name)
|
|||
SessionData* sd = reinterpret_cast<SessionData*>(userData);
|
||||
std::string characters;
|
||||
if(sd->_stm->needsCharactersBuffering()) {
|
||||
characters = Util::trim(sd->_charactersStack.top());
|
||||
characters = util::trim(sd->_charactersStack.top());
|
||||
sd->_charactersStack.pop();
|
||||
}
|
||||
sd->_stm->endElement(name, characters);
|
||||
|
|
|
@ -158,7 +158,7 @@ std::string FeatureConfig::featureSummary() const
|
|||
s += ", ";
|
||||
}
|
||||
}
|
||||
return Util::trim(s, ", ");
|
||||
return util::trim(s, ", ");
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -106,13 +106,13 @@ bool File::mkdirs() {
|
|||
return false;
|
||||
}
|
||||
std::vector<std::string> dirs;
|
||||
split(name, std::back_inserter(dirs), "/");
|
||||
util::split(name, std::back_inserter(dirs), "/");
|
||||
if(!dirs.size()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string accDir;
|
||||
if(Util::startsWith(name, A2STR::SLASH_C)) {
|
||||
if(util::startsWith(name, A2STR::SLASH_C)) {
|
||||
accDir = A2STR::SLASH_C;
|
||||
}
|
||||
for(std::vector<std::string>::const_iterator itr = dirs.begin();
|
||||
|
|
|
@ -61,7 +61,7 @@ bool FileAllocationCommand::executeInternal()
|
|||
if(_fileAllocationEntry->finished()) {
|
||||
logger->debug(MSG_ALLOCATION_COMPLETED,
|
||||
_timer.difference(),
|
||||
Util::itos(_requestGroup->getTotalLength(), true).c_str());
|
||||
util::itos(_requestGroup->getTotalLength(), true).c_str());
|
||||
_e->_fileAllocationMan->dropPickedEntry();
|
||||
|
||||
std::deque<Command*> commands;
|
||||
|
|
|
@ -61,7 +61,7 @@ FileEntry::~FileEntry() {}
|
|||
|
||||
void FileEntry::setupDir()
|
||||
{
|
||||
Util::mkdirs(File(path).getDirname());
|
||||
util::mkdirs(File(path).getDirname());
|
||||
}
|
||||
|
||||
FileEntry& FileEntry::operator=(const FileEntry& entry)
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
|
||||
virtual std::string decorate(unsigned int number)
|
||||
{
|
||||
std::string s = Util::uitos(number);
|
||||
std::string s = util::uitos(number);
|
||||
while(s.size() < _width) {
|
||||
s.insert(0, "0");
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ bool FtpConnection::sendCwd()
|
|||
if(_baseWorkingDir != "/") {
|
||||
request += _baseWorkingDir;
|
||||
}
|
||||
request += Util::urldecode(req->getDir());
|
||||
request += util::urldecode(req->getDir());
|
||||
request += "\r\n";
|
||||
logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
|
||||
_socketBuffer.feedSendBuffer(request);
|
||||
|
@ -152,7 +152,7 @@ bool FtpConnection::sendMdtm()
|
|||
{
|
||||
if(_socketBuffer.sendBufferIsEmpty()) {
|
||||
std::string request = "MDTM ";
|
||||
request += Util::urlencode(req->getFile());
|
||||
request += util::urlencode(req->getFile());
|
||||
request += "\r\n";
|
||||
logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
|
||||
_socketBuffer.feedSendBuffer(request);
|
||||
|
@ -165,7 +165,7 @@ bool FtpConnection::sendSize()
|
|||
{
|
||||
if(_socketBuffer.sendBufferIsEmpty()) {
|
||||
std::string request = "SIZE ";
|
||||
request += Util::urldecode(req->getFile());
|
||||
request += util::urldecode(req->getFile());
|
||||
request += "\r\n";
|
||||
logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
|
||||
_socketBuffer.feedSendBuffer(request);
|
||||
|
@ -204,17 +204,17 @@ bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
|
|||
&ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]);
|
||||
serverSocket->getAddrInfo(addrinfo);
|
||||
std::string request = "PORT ";
|
||||
request += Util::uitos(ipaddr[0]);
|
||||
request += util::uitos(ipaddr[0]);
|
||||
request += ",";
|
||||
request += Util::uitos(ipaddr[1]);
|
||||
request += util::uitos(ipaddr[1]);
|
||||
request += ",";
|
||||
request += Util::uitos(ipaddr[2]);
|
||||
request += util::uitos(ipaddr[2]);
|
||||
request += ",";
|
||||
request += Util::uitos(ipaddr[3]);
|
||||
request += util::uitos(ipaddr[3]);
|
||||
request += ",";
|
||||
request += Util::uitos(addrinfo.second/256);
|
||||
request += util::uitos(addrinfo.second/256);
|
||||
request += ",";
|
||||
request += Util::uitos(addrinfo.second%256);
|
||||
request += util::uitos(addrinfo.second%256);
|
||||
request += "\r\n";
|
||||
logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
|
||||
_socketBuffer.feedSendBuffer(request);
|
||||
|
@ -230,7 +230,7 @@ bool FtpConnection::sendRest(const SegmentHandle& segment)
|
|||
if(segment.isNull()) {
|
||||
request += "0";
|
||||
} else {
|
||||
request += Util::itos(segment->getPositionToWrite());
|
||||
request += util::itos(segment->getPositionToWrite());
|
||||
}
|
||||
request += "\r\n";
|
||||
|
||||
|
@ -245,7 +245,7 @@ bool FtpConnection::sendRetr()
|
|||
{
|
||||
if(_socketBuffer.sendBufferIsEmpty()) {
|
||||
std::string request = "RETR ";
|
||||
request += Util::urldecode(req->getFile());
|
||||
request += util::urldecode(req->getFile());
|
||||
request += "\r\n";
|
||||
logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
|
||||
_socketBuffer.feedSendBuffer(request);
|
||||
|
@ -286,7 +286,7 @@ FtpConnection::findEndOfResponse(unsigned int status,
|
|||
std::string::size_type p;
|
||||
|
||||
std::string endPattern = A2STR::CRLF;
|
||||
endPattern += Util::uitos(status);
|
||||
endPattern += util::uitos(status);
|
||||
endPattern += " ";
|
||||
p = buf.find(endPattern);
|
||||
if(p == std::string::npos) {
|
||||
|
@ -378,8 +378,8 @@ unsigned int FtpConnection::receiveSizeResponse(uint64_t& size)
|
|||
std::pair<unsigned int, std::string> response;
|
||||
if(bulkReceiveResponse(response)) {
|
||||
if(response.first == 213) {
|
||||
std::pair<std::string, std::string> rp = Util::split(response.second," ");
|
||||
size = Util::parseULLInt(rp.second);
|
||||
std::pair<std::string, std::string> rp = util::split(response.second," ");
|
||||
size = util::parseULLInt(rp.second);
|
||||
}
|
||||
return response.first;
|
||||
} else {
|
||||
|
@ -400,17 +400,17 @@ unsigned int FtpConnection::receiveMdtmResponse(Time& time)
|
|||
// and included strptime doesn't parse data for this format.
|
||||
struct tm tm;
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
tm.tm_sec = Util::parseInt(&buf[12]);
|
||||
tm.tm_sec = util::parseInt(&buf[12]);
|
||||
buf[12] = '\0';
|
||||
tm.tm_min = Util::parseInt(&buf[10]);
|
||||
tm.tm_min = util::parseInt(&buf[10]);
|
||||
buf[10] = '\0';
|
||||
tm.tm_hour = Util::parseInt(&buf[8]);
|
||||
tm.tm_hour = util::parseInt(&buf[8]);
|
||||
buf[8] = '\0';
|
||||
tm.tm_mday = Util::parseInt(&buf[6]);
|
||||
tm.tm_mday = util::parseInt(&buf[6]);
|
||||
buf[6] = '\0';
|
||||
tm.tm_mon = Util::parseInt(&buf[4])-1;
|
||||
tm.tm_mon = util::parseInt(&buf[4])-1;
|
||||
buf[4] = '\0';
|
||||
tm.tm_year = Util::parseInt(&buf[0])-1900;
|
||||
tm.tm_year = util::parseInt(&buf[0])-1900;
|
||||
time = Time(timegm(&tm));
|
||||
} else {
|
||||
time = Time::null();
|
||||
|
@ -435,13 +435,13 @@ unsigned int FtpConnection::receivePasvResponse(std::pair<std::string, uint16_t>
|
|||
"(%u,%u,%u,%u,%u,%u).",
|
||||
&h1, &h2, &h3, &h4, &p1, &p2);
|
||||
// ip address
|
||||
dest.first = Util::uitos(h1);
|
||||
dest.first = util::uitos(h1);
|
||||
dest.first += ".";
|
||||
dest.first += Util::uitos(h2);
|
||||
dest.first += util::uitos(h2);
|
||||
dest.first += ".";
|
||||
dest.first += Util::uitos(h3);
|
||||
dest.first += util::uitos(h3);
|
||||
dest.first += ".";
|
||||
dest.first += Util::uitos(h4);
|
||||
dest.first += util::uitos(h4);
|
||||
// port number
|
||||
dest.second = 256*p1+p2;
|
||||
} else {
|
||||
|
|
|
@ -337,7 +337,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
|||
if(getOption()->get(PREF_OUT).empty()) {
|
||||
_fileEntry->setPath
|
||||
(strconcat(getDownloadContext()->getDir(),
|
||||
"/", Util::urldecode(req->getFile())));
|
||||
"/", util::urldecode(req->getFile())));
|
||||
}
|
||||
_requestGroup->preDownloadProcessing();
|
||||
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
||||
|
@ -430,7 +430,7 @@ bool FtpNegotiationCommand::recvSize() {
|
|||
|
||||
if(size > INT64_MAX) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(EX_TOO_LARGE_FILE, Util::uitos(size, true).c_str()).str());
|
||||
(StringFormat(EX_TOO_LARGE_FILE, util::uitos(size, true).c_str()).str());
|
||||
}
|
||||
if(_requestGroup->getPieceStorage().isNull()) {
|
||||
|
||||
|
|
|
@ -75,15 +75,15 @@ std::string HandshakeExtensionMessage::toString() const
|
|||
{
|
||||
std::string s = getExtensionName();
|
||||
if(!_clientVersion.empty()) {
|
||||
strappend(s, " client=", Util::urlencode(_clientVersion));
|
||||
strappend(s, " client=", util::urlencode(_clientVersion));
|
||||
}
|
||||
if(_tcpPort > 0) {
|
||||
strappend(s, ", tcpPort=", Util::uitos(_tcpPort));
|
||||
strappend(s, ", tcpPort=", util::uitos(_tcpPort));
|
||||
}
|
||||
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin();
|
||||
itr != _extensions.end(); ++itr) {
|
||||
const std::map<std::string, uint8_t>::value_type& vt = *itr;
|
||||
strappend(s, ", ", vt.first, "=", Util::uitos(vt.second));
|
||||
strappend(s, ", ", vt.first, "=", util::uitos(vt.second));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length)
|
|||
}
|
||||
HandshakeExtensionMessageHandle msg(new HandshakeExtensionMessage());
|
||||
msg->_logger->debug("Creating HandshakeExtensionMessage from %s",
|
||||
Util::urlencode(data, length).c_str());
|
||||
util::urlencode(data, length).c_str());
|
||||
const BDE dict = bencode::decode(data+1, length-1);
|
||||
if(!dict.isDict()) {
|
||||
throw DL_ABORT_EX("Unexpected payload format for extended message handshake");
|
||||
|
|
|
@ -80,9 +80,9 @@ std::string HttpConnection::eraseConfidentialInfo(const std::string& request)
|
|||
while(getline(istr, line)) {
|
||||
static const std::string AUTH_HEADER("Authorization: Basic");
|
||||
static const std::string PROXY_AUTH_HEADER("Proxy-Authorization: Basic");
|
||||
if(Util::startsWith(line, AUTH_HEADER)) {
|
||||
if(util::startsWith(line, AUTH_HEADER)) {
|
||||
result += "Authorization: Basic ********\n";
|
||||
} else if(Util::startsWith(line, PROXY_AUTH_HEADER)) {
|
||||
} else if(util::startsWith(line, PROXY_AUTH_HEADER)) {
|
||||
result += "Proxy-Authorization: Basic ********\n";
|
||||
} else {
|
||||
strappend(result, line, "\n");
|
||||
|
|
|
@ -85,16 +85,16 @@ const std::string HttpHeader::S401("401");
|
|||
const std::string HttpHeader::S404("404");
|
||||
|
||||
void HttpHeader::put(const std::string& name, const std::string& value) {
|
||||
std::multimap<std::string, std::string>::value_type vt(Util::toLower(name), value);
|
||||
std::multimap<std::string, std::string>::value_type vt(util::toLower(name), value);
|
||||
table.insert(vt);
|
||||
}
|
||||
|
||||
bool HttpHeader::defined(const std::string& name) const {
|
||||
return table.count(Util::toLower(name)) >= 1;
|
||||
return table.count(util::toLower(name)) >= 1;
|
||||
}
|
||||
|
||||
const std::string& HttpHeader::getFirst(const std::string& name) const {
|
||||
std::multimap<std::string, std::string>::const_iterator itr = table.find(Util::toLower(name));
|
||||
std::multimap<std::string, std::string>::const_iterator itr = table.find(util::toLower(name));
|
||||
if(itr == table.end()) {
|
||||
return A2STR::NIL;
|
||||
} else {
|
||||
|
@ -105,7 +105,7 @@ const std::string& HttpHeader::getFirst(const std::string& name) const {
|
|||
std::deque<std::string> HttpHeader::get(const std::string& name) const {
|
||||
std::deque<std::string> v;
|
||||
|
||||
std::string n(Util::toLower(name));
|
||||
std::string n(util::toLower(name));
|
||||
|
||||
std::multimap<std::string, std::string>::const_iterator first =
|
||||
table.lower_bound(n);
|
||||
|
@ -128,7 +128,7 @@ uint64_t HttpHeader::getFirstAsULLInt(const std::string& name) const {
|
|||
if(value.empty()) {
|
||||
return 0;
|
||||
} else {
|
||||
return Util::parseULLInt(value);
|
||||
return util::parseULLInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ RangeHandle HttpHeader::getRange() const
|
|||
if(contentLengthStr.empty()) {
|
||||
return SharedHandle<Range>(new Range());
|
||||
} else {
|
||||
uint64_t contentLength = Util::parseULLInt(contentLengthStr);
|
||||
uint64_t contentLength = util::parseULLInt(contentLengthStr);
|
||||
if(contentLength == 0) {
|
||||
return SharedHandle<Range>(new Range());
|
||||
} else {
|
||||
|
@ -154,7 +154,7 @@ RangeHandle HttpHeader::getRange() const
|
|||
// but some server returns '100-199/100', omitting bytes-unit sepcifier
|
||||
// 'bytes'.
|
||||
std::pair<std::string, std::string> splist;
|
||||
Util::split(splist, rangeStr, ' ');
|
||||
util::split(splist, rangeStr, ' ');
|
||||
if(splist.second.empty()) {
|
||||
// we assume bytes-unit specifier omitted.
|
||||
byteRangeSpec = splist.first;
|
||||
|
@ -163,14 +163,14 @@ RangeHandle HttpHeader::getRange() const
|
|||
}
|
||||
}
|
||||
std::pair<std::string, std::string> byteRangeSpecPair;
|
||||
Util::split(byteRangeSpecPair, byteRangeSpec, '/');
|
||||
util::split(byteRangeSpecPair, byteRangeSpec, '/');
|
||||
|
||||
std::pair<std::string, std::string> byteRangeRespSpecPair;
|
||||
Util::split(byteRangeRespSpecPair, byteRangeSpecPair.first, '-');
|
||||
util::split(byteRangeRespSpecPair, byteRangeSpecPair.first, '-');
|
||||
|
||||
off_t startByte = Util::parseLLInt(byteRangeRespSpecPair.first);
|
||||
off_t endByte = Util::parseLLInt(byteRangeRespSpecPair.second);
|
||||
uint64_t entityLength = Util::parseULLInt(byteRangeSpecPair.second);
|
||||
off_t startByte = util::parseLLInt(byteRangeRespSpecPair.first);
|
||||
off_t endByte = util::parseLLInt(byteRangeRespSpecPair.second);
|
||||
uint64_t entityLength = util::parseULLInt(byteRangeSpecPair.second);
|
||||
|
||||
return SharedHandle<Range>(new Range(startByte, endByte, entityLength));
|
||||
}
|
||||
|
@ -199,12 +199,12 @@ void HttpHeader::fill(std::istream& in)
|
|||
{
|
||||
std::string line;
|
||||
while(std::getline(in, line)) {
|
||||
line = Util::trim(line);
|
||||
line = util::trim(line);
|
||||
if(line.empty()) {
|
||||
continue;
|
||||
}
|
||||
std::pair<std::string, std::string> hp;
|
||||
Util::split(hp, line, ':');
|
||||
util::split(hp, line, ':');
|
||||
put(hp.first, hp.second);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ SharedHandle<HttpHeader> HttpHeaderProcessor::getHttpRequestHeader()
|
|||
throw DL_RETRY_EX(EX_NO_STATUS_HEADER);
|
||||
}
|
||||
std::vector<std::string> firstLine;
|
||||
split(_buf.substr(0, delimpos), std::back_inserter(firstLine), " ", true);
|
||||
util::split(_buf.substr(0, delimpos), std::back_inserter(firstLine)," ",true);
|
||||
if(firstLine.size() != 3) {
|
||||
throw DL_ABORT_EX("Malformed HTTP request header.");
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ static std::string getHostText(const std::string& host, uint16_t port)
|
|||
{
|
||||
std::string hosttext = host;
|
||||
if(!(port == 80 || port == 443)) {
|
||||
strappend(hosttext, ":", Util::uitos(port));
|
||||
strappend(hosttext, ":", util::uitos(port));
|
||||
}
|
||||
return hosttext;
|
||||
}
|
||||
|
@ -138,7 +138,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::urlencode(_authConfig->getUser())+"@");
|
||||
requestLine += uri;
|
||||
} else {
|
||||
requestLine += getCurrentURI();
|
||||
|
@ -183,10 +183,10 @@ std::string HttpRequest::createRequest()
|
|||
if(!segment.isNull() && segment->getLength() > 0 &&
|
||||
(request->isPipeliningEnabled() || getStartByte() > 0)) {
|
||||
requestLine += "Range: bytes=";
|
||||
requestLine += Util::itos(getStartByte());
|
||||
requestLine += util::itos(getStartByte());
|
||||
requestLine += "-";
|
||||
if(request->isPipeliningEnabled()) {
|
||||
requestLine += Util::itos(getEndByte());
|
||||
requestLine += util::itos(getEndByte());
|
||||
}
|
||||
requestLine += "\r\n";
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ std::string HttpRequest::createProxyRequest() const
|
|||
{
|
||||
assert(!_proxyRequest.isNull());
|
||||
std::string hostport = getURIHost();
|
||||
strappend(hostport, ":", Util::uitos(getPort()));
|
||||
strappend(hostport, ":", util::uitos(getPort()));
|
||||
|
||||
std::string requestLine = "CONNECT ";
|
||||
strappend(requestLine, hostport, " HTTP/1.1\r\n");
|
||||
|
@ -278,7 +278,7 @@ void HttpRequest::disableContentEncoding()
|
|||
void HttpRequest::addHeader(const std::string& headersString)
|
||||
{
|
||||
std::vector<std::string> headers;
|
||||
split(headersString, std::back_inserter(headers), "\n", true);
|
||||
util::split(headersString, std::back_inserter(headers), "\n", true);
|
||||
_headers.insert(_headers.end(), headers.begin(), headers.end());
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ void HttpResponse::validateResponse() const
|
|||
if(!httpHeader->defined(HttpHeader::LOCATION)) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(EX_LOCATION_HEADER_REQUIRED,
|
||||
Util::parseUInt(status)).str());
|
||||
util::parseUInt(status)).str());
|
||||
}
|
||||
} else if(!httpHeader->defined(HttpHeader::TRANSFER_ENCODING)) {
|
||||
// compare the received range against the requested range
|
||||
|
@ -85,12 +85,12 @@ void HttpResponse::validateResponse() const
|
|||
throw DL_ABORT_EX
|
||||
(StringFormat
|
||||
(EX_INVALID_RANGE_HEADER,
|
||||
Util::itos(httpRequest->getStartByte(), true).c_str(),
|
||||
Util::itos(httpRequest->getEndByte(), true).c_str(),
|
||||
Util::uitos(httpRequest->getEntityLength(), true).c_str(),
|
||||
Util::itos(responseRange->getStartByte(), true).c_str(),
|
||||
Util::itos(responseRange->getEndByte(), true).c_str(),
|
||||
Util::uitos(responseRange->getEntityLength(), true).c_str()).str());
|
||||
util::itos(httpRequest->getStartByte(), true).c_str(),
|
||||
util::itos(httpRequest->getEndByte(), true).c_str(),
|
||||
util::uitos(httpRequest->getEntityLength(), true).c_str(),
|
||||
util::itos(responseRange->getStartByte(), true).c_str(),
|
||||
util::itos(responseRange->getEndByte(), true).c_str(),
|
||||
util::uitos(responseRange->getEntityLength(), true).c_str()).str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,10 +98,10 @@ void HttpResponse::validateResponse() const
|
|||
std::string HttpResponse::determinFilename() const
|
||||
{
|
||||
std::string contentDisposition =
|
||||
Util::getContentDispositionFilename
|
||||
util::getContentDispositionFilename
|
||||
(httpHeader->getFirst(HttpHeader::CONTENT_DISPOSITION));
|
||||
if(contentDisposition.empty()) {
|
||||
std::string file = Util::urldecode(httpRequest->getFile());
|
||||
std::string file = util::urldecode(httpRequest->getFile());
|
||||
if(file.empty()) {
|
||||
return "index.html";
|
||||
} else {
|
||||
|
@ -110,7 +110,7 @@ std::string HttpResponse::determinFilename() const
|
|||
} else {
|
||||
logger->info(MSG_CONTENT_DISPOSITION_DETECTED,
|
||||
cuid, contentDisposition.c_str());
|
||||
return Util::urldecode(contentDisposition);
|
||||
return util::urldecode(contentDisposition);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ std::string HttpResponse::getContentType() const
|
|||
return A2STR::NIL;
|
||||
} else {
|
||||
return
|
||||
Util::split(httpHeader->getFirst(HttpHeader::CONTENT_TYPE), ";").first;
|
||||
util::split(httpHeader->getFirst(HttpHeader::CONTENT_TYPE), ";").first;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ Time HttpResponse::getLastModifiedTime() const
|
|||
bool HttpResponse::supportsPersistentConnection() const
|
||||
{
|
||||
std::string connection =
|
||||
Util::toLower(httpHeader->getFirst(HttpHeader::CONNECTION));
|
||||
util::toLower(httpHeader->getFirst(HttpHeader::CONNECTION));
|
||||
std::string version = httpHeader->getVersion();
|
||||
|
||||
return
|
||||
|
@ -265,7 +265,7 @@ bool HttpResponse::supportsPersistentConnection() const
|
|||
(version == HttpHeader::HTTP_1_1 ||
|
||||
connection.find("keep-alive") != std::string::npos) &&
|
||||
(!httpRequest->isProxyRequestSet() ||
|
||||
Util::toLower(httpHeader->getFirst("Proxy-Connection")).find("keep-alive")
|
||||
util::toLower(httpHeader->getFirst("Proxy-Connection")).find("keep-alive")
|
||||
!= std::string::npos);
|
||||
}
|
||||
|
||||
|
|
|
@ -196,8 +196,8 @@ void HttpResponseCommand::updateLastModifiedTime(const Time& lastModified)
|
|||
static bool fileIsGzipped(const SharedHandle<HttpResponse>& httpResponse)
|
||||
{
|
||||
std::string filename =
|
||||
Util::toLower(httpResponse->getHttpRequest()->getRequest()->getFile());
|
||||
return Util::endsWith(filename, ".gz") || Util::endsWith(filename, ".tgz");
|
||||
util::toLower(httpResponse->getHttpRequest()->getRequest()->getFile());
|
||||
return util::endsWith(filename, ".gz") || util::endsWith(filename, ".tgz");
|
||||
}
|
||||
|
||||
bool HttpResponseCommand::shouldInflateContentEncoding
|
||||
|
|
|
@ -128,7 +128,7 @@ bool HttpServer::supportsPersistentConnection() const
|
|||
}
|
||||
|
||||
std::string connection =
|
||||
Util::toLower(_lastRequestHeader->getFirst(HttpHeader::CONNECTION));
|
||||
util::toLower(_lastRequestHeader->getFirst(HttpHeader::CONNECTION));
|
||||
|
||||
return connection.find(HttpHeader::CLOSE) == std::string::npos &&
|
||||
(_lastRequestHeader->getVersion() == HttpHeader::HTTP_1_1 ||
|
||||
|
@ -148,14 +148,14 @@ void HttpServer::feedResponse(const std::string& status,
|
|||
std::string header = "HTTP/1.1 ";
|
||||
strappend(header, status, "\r\n",
|
||||
"Content-Type: ", contentType, "\r\n",
|
||||
"Content-Length: ", Util::uitos(text.size()), "\r\n");
|
||||
"Content-Length: ", util::uitos(text.size()), "\r\n");
|
||||
|
||||
if(!supportsPersistentConnection()) {
|
||||
header += "Connection: close\r\n";
|
||||
}
|
||||
if(!headers.empty()) {
|
||||
header += headers;
|
||||
if(!Util::endsWith(headers, "\r\n")) {
|
||||
if(!util::endsWith(headers, "\r\n")) {
|
||||
header += "\r\n";
|
||||
}
|
||||
}
|
||||
|
@ -188,12 +188,12 @@ bool HttpServer::authenticate()
|
|||
if(authHeader.empty()) {
|
||||
return false;
|
||||
}
|
||||
std::pair<std::string, std::string> p = Util::split(authHeader, " ");
|
||||
std::pair<std::string, std::string> p = util::split(authHeader, " ");
|
||||
if(p.first != "Basic") {
|
||||
return false;
|
||||
}
|
||||
std::string userpass = Base64::decode(p.second);
|
||||
std::pair<std::string, std::string> userpassPair = Util::split(userpass, ":");
|
||||
std::pair<std::string, std::string> userpassPair = util::split(userpass, ":");
|
||||
return _username == userpassPair.first && _password == userpassPair.second;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ bool HttpServerCommand::execute()
|
|||
logger->info("Request too long. ContentLength=%s."
|
||||
" See --xml-rpc-max-request-size option to loose"
|
||||
" this limitation.",
|
||||
Util::uitos(_httpServer->getContentLength()).c_str());
|
||||
util::uitos(_httpServer->getContentLength()).c_str());
|
||||
return true;
|
||||
}
|
||||
Command* command = new HttpServerBodyCommand(cuid, _httpServer, _e,
|
||||
|
|
|
@ -171,7 +171,7 @@ bool HttpSkipResponseCommand::processResponse()
|
|||
throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
|
||||
downloadresultcode::RESOURCE_NOT_FOUND);
|
||||
} else {
|
||||
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, Util::parseUInt(_httpResponse->getResponseStatus())).str());
|
||||
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, util::parseUInt(_httpResponse->getResponseStatus())).str());
|
||||
}
|
||||
} else {
|
||||
return prepareForRetry(0);
|
||||
|
|
|
@ -62,7 +62,7 @@ size_t IndexBtMessage::getMessageLength()
|
|||
|
||||
std::string IndexBtMessage::toString() const
|
||||
{
|
||||
return strconcat(getName(), " index=", Util::itos(_index));
|
||||
return strconcat(getName(), " index=", util::itos(_index));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -79,7 +79,7 @@ void IteratableChecksumValidator::validateChunk()
|
|||
_ctx->digestUpdate(_buffer, length);
|
||||
_currentOffset += length;
|
||||
if(finished()) {
|
||||
std::string actualChecksum = Util::toHex((const unsigned char*)_ctx->digestFinal().c_str(), _ctx->digestLength());
|
||||
std::string actualChecksum = util::toHex((const unsigned char*)_ctx->digestFinal().c_str(), _ctx->digestLength());
|
||||
if(_dctx->getChecksum() == actualChecksum) {
|
||||
_pieceStorage->markAllPiecesDone();
|
||||
} else {
|
||||
|
@ -109,7 +109,7 @@ void IteratableChecksumValidator::init()
|
|||
{
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
free(_buffer);
|
||||
_buffer = (unsigned char*)Util::allocateAlignedMemory(ALIGNMENT, BUFSIZE);
|
||||
_buffer = (unsigned char*)util::allocateAlignedMemory(ALIGNMENT, BUFSIZE);
|
||||
#else // !HAVE_POSIX_MEMALIGN
|
||||
delete [] _buffer;
|
||||
_buffer = new unsigned char[BUFSIZE];
|
||||
|
|
|
@ -88,7 +88,7 @@ void IteratableChunkChecksumValidator::validateChunk()
|
|||
} else {
|
||||
_logger->info(EX_INVALID_CHUNK_CHECKSUM,
|
||||
_currentIndex,
|
||||
Util::itos(getCurrentOffset(), true).c_str(),
|
||||
util::itos(getCurrentOffset(), true).c_str(),
|
||||
_dctx->getPieceHashes()[_currentIndex].c_str(),
|
||||
actualChecksum.c_str());
|
||||
_bitfield->unsetBit(_currentIndex);
|
||||
|
@ -122,7 +122,7 @@ void IteratableChunkChecksumValidator::init()
|
|||
{
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
free(_buffer);
|
||||
_buffer = (unsigned char*)Util::allocateAlignedMemory(ALIGNMENT, BUFSIZE);
|
||||
_buffer = (unsigned char*)util::allocateAlignedMemory(ALIGNMENT, BUFSIZE);
|
||||
#else // !HAVE_POSIX_MEMALIGN
|
||||
delete [] _buffer;
|
||||
_buffer = new unsigned char[BUFSIZE];
|
||||
|
@ -166,7 +166,7 @@ std::string IteratableChunkChecksumValidator::digest(off_t offset, size_t length
|
|||
curoffset += r;
|
||||
woffset = 0;
|
||||
}
|
||||
return Util::toHex((const unsigned char*)_ctx->digestFinal().c_str(), _ctx->digestLength());
|
||||
return util::toHex((const unsigned char*)_ctx->digestFinal().c_str(), _ctx->digestLength());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -453,7 +453,7 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
|
|||
createReq23Hash(md, torrentAttrs[bittorrent::INFO_HASH].uc());
|
||||
if(memcmp(md, rbufptr, sizeof(md)) == 0) {
|
||||
_logger->debug("CUID#%d - info hash found: %s", _cuid,
|
||||
Util::toHex(torrentAttrs[bittorrent::INFO_HASH].s()).c_str());
|
||||
util::toHex(torrentAttrs[bittorrent::INFO_HASH].s()).c_str());
|
||||
downloadContext = *i;
|
||||
break;
|
||||
}
|
||||
|
@ -577,7 +577,7 @@ void MSEHandshake::verifyVC(const unsigned char* vcbuf)
|
|||
_decryptor->decrypt(vc, sizeof(vc), vcbuf, sizeof(vc));
|
||||
if(memcmp(VC, vc, sizeof(VC)) != 0) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("Invalid VC: %s", Util::toHex(vc, VC_LENGTH).c_str()).str());
|
||||
(StringFormat("Invalid VC: %s", util::toHex(vc, VC_LENGTH).c_str()).str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ std::string MessageDigestHelper::digest(MessageDigestContext* ctx,
|
|||
ctx->digestUpdate(BUF, readLength);
|
||||
}
|
||||
std::string rawMD = ctx->digestFinal();
|
||||
return Util::toHex((const unsigned char*)rawMD.c_str(), rawMD.size());
|
||||
return util::toHex((const unsigned char*)rawMD.c_str(), rawMD.size());
|
||||
}
|
||||
|
||||
std::string MessageDigestHelper::digest(const std::string& algo, const std::string& filename)
|
||||
|
@ -123,7 +123,7 @@ std::string MessageDigestHelper::digest(const std::string& algo, const void* dat
|
|||
ctx.digestInit();
|
||||
ctx.digestUpdate(data, length);
|
||||
std::string rawMD = ctx.digestFinal();
|
||||
return Util::toHex((const unsigned char*)rawMD.c_str(), rawMD.size());
|
||||
return util::toHex((const unsigned char*)rawMD.c_str(), rawMD.size());
|
||||
}
|
||||
|
||||
void MessageDigestHelper::digest(unsigned char* md, size_t mdLength,
|
||||
|
|
|
@ -130,7 +130,7 @@ Metalink2RequestGroup::createRequestGroup
|
|||
return;
|
||||
}
|
||||
std::deque<int32_t> selectIndexes =
|
||||
Util::parseIntRange(option->get(PREF_SELECT_FILE)).flush();
|
||||
util::parseIntRange(option->get(PREF_SELECT_FILE)).flush();
|
||||
bool useIndex;
|
||||
if(selectIndexes.size()) {
|
||||
useIndex = true;
|
||||
|
@ -143,8 +143,8 @@ Metalink2RequestGroup::createRequestGroup
|
|||
SharedHandle<MetalinkEntry>& entry = *itr;
|
||||
if(option->defined(PREF_METALINK_LOCATION)) {
|
||||
std::deque<std::string> locations;
|
||||
split(option->get(PREF_METALINK_LOCATION), std::back_inserter(locations),
|
||||
",", true);
|
||||
util::split(option->get(PREF_METALINK_LOCATION),
|
||||
std::back_inserter(locations), ",", true);
|
||||
entry->setLocationPreference(locations, 100);
|
||||
}
|
||||
if(option->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) {
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
AddLocationPreference(const std::deque<std::string>& locations, int preferenceToAdd):
|
||||
_locations(locations), _preferenceToAdd(preferenceToAdd)
|
||||
{
|
||||
std::transform(_locations.begin(), _locations.end(), _locations.begin(), Util::toUpper);
|
||||
std::transform(_locations.begin(), _locations.end(), _locations.begin(), util::toUpper);
|
||||
std::sort(_locations.begin(), _locations.end());
|
||||
}
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ void MetalinkParserController::setFileNameOfEntry(const std::string& filename)
|
|||
return;
|
||||
}
|
||||
std::vector<std::string> elements;
|
||||
split(filename, std::back_inserter(elements), "/");
|
||||
std::string path = Util::joinPath(elements.begin(), elements.end());
|
||||
util::split(filename, std::back_inserter(elements), "/");
|
||||
std::string path = util::joinPath(elements.begin(), elements.end());
|
||||
|
||||
if(_tEntry->file.isNull()) {
|
||||
_tEntry->file.reset(new FileEntry(path, 0, 0));
|
||||
|
|
|
@ -131,7 +131,7 @@ void FileMetalinkParserState::beginElement
|
|||
maxConnections = -1;
|
||||
} else {
|
||||
try {
|
||||
maxConnections = Util::parseInt((*itr).second);
|
||||
maxConnections = util::parseInt((*itr).second);
|
||||
} catch(RecoverableException& e) {
|
||||
maxConnections = -1;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ void SizeMetalinkParserState::endElement
|
|||
const std::string& characters)
|
||||
{
|
||||
try {
|
||||
stm->setFileLengthOfEntry(Util::parseLLInt(characters));
|
||||
stm->setFileLengthOfEntry(util::parseLLInt(characters));
|
||||
} catch(RecoverableException& e) {
|
||||
// current metalink specification doesn't require size element.
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ void VerificationMetalinkParserState::beginElement
|
|||
if(itr == attrs.end()) {
|
||||
return;
|
||||
} else {
|
||||
length = Util::parseInt((*itr).second);
|
||||
length = util::parseInt((*itr).second);
|
||||
}
|
||||
}
|
||||
std::string type;
|
||||
|
@ -314,7 +314,7 @@ void PiecesMetalinkParserState::beginElement
|
|||
stm->cancelChunkChecksumTransaction();
|
||||
} else {
|
||||
try {
|
||||
stm->createNewHashOfChunkChecksum(Util::parseInt((*itr).second));
|
||||
stm->createNewHashOfChunkChecksum(util::parseInt((*itr).second));
|
||||
} catch(RecoverableException& e) {
|
||||
stm->cancelChunkChecksumTransaction();
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ void ResourcesMetalinkParserState::beginElement
|
|||
std::map<std::string, std::string>::const_iterator itr =
|
||||
attrs.find(LOCATION);
|
||||
if(itr != attrs.end()) {
|
||||
location = Util::toUpper((*itr).second);
|
||||
location = util::toUpper((*itr).second);
|
||||
}
|
||||
}
|
||||
int preference;
|
||||
|
@ -398,7 +398,7 @@ void ResourcesMetalinkParserState::beginElement
|
|||
preference = 0;
|
||||
} else {
|
||||
try {
|
||||
preference = Util::parseInt((*itr).second);
|
||||
preference = util::parseInt((*itr).second);
|
||||
} catch(RecoverableException& e) {
|
||||
preference = 0;
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ void ResourcesMetalinkParserState::beginElement
|
|||
maxConnections = -1;
|
||||
} else {
|
||||
try {
|
||||
maxConnections = Util::parseInt((*itr).second);
|
||||
maxConnections = util::parseInt((*itr).second);
|
||||
} catch(RecoverableException& e) {
|
||||
maxConnections = -1;
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ void MultiDiskAdaptor::openIfNot
|
|||
{
|
||||
if(!entry->isOpen()) {
|
||||
// logger->debug("DiskWriterEntry: Cache MISS. offset=%s",
|
||||
// Util::itos(entry->getFileEntry()->getOffset()).c_str());
|
||||
// util::itos(entry->getFileEntry()->getOffset()).c_str());
|
||||
|
||||
size_t numOpened = _openedDiskWriterEntries.size();
|
||||
(entry.get()->*open)();
|
||||
|
@ -289,7 +289,7 @@ void MultiDiskAdaptor::openIfNot
|
|||
}
|
||||
} else {
|
||||
// logger->debug("DiskWriterEntry: Cache HIT. offset=%s",
|
||||
// Util::itos(entry->getFileEntry()->getOffset()).c_str());
|
||||
// util::itos(entry->getFileEntry()->getOffset()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ findFirstDiskWriterEntry(const DiskWriterEntries& diskWriterEntries, off_t offse
|
|||
if(!isInRange(*first, offset)) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(EX_FILE_OFFSET_OUT_OF_RANGE,
|
||||
Util::itos(offset, true).c_str()).str());
|
||||
util::itos(offset, true).c_str()).str());
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ static void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
|
|||
{
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("DiskWriter for offset=%s, filename=%s is not opened.",
|
||||
Util::itos(offset).c_str(),
|
||||
util::itos(offset).c_str(),
|
||||
e->getFilePath().c_str()).str());
|
||||
}
|
||||
|
||||
|
|
|
@ -170,8 +170,8 @@ downloadresultcode::RESULT MultiUrlRequestInfo::execute()
|
|||
// This is done every 1 second. At the same time, it removes finished/error
|
||||
// RequestGroup from DownloadEngine.
|
||||
|
||||
Util::setGlobalSignalHandler(SIGINT, handler, 0);
|
||||
Util::setGlobalSignalHandler(SIGTERM, handler, 0);
|
||||
util::setGlobalSignalHandler(SIGINT, handler, 0);
|
||||
util::setGlobalSignalHandler(SIGTERM, handler, 0);
|
||||
|
||||
e->run();
|
||||
|
||||
|
@ -199,8 +199,8 @@ downloadresultcode::RESULT MultiUrlRequestInfo::execute()
|
|||
} catch(RecoverableException& e) {
|
||||
_logger->error(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
Util::setGlobalSignalHandler(SIGINT, SIG_DFL, 0);
|
||||
Util::setGlobalSignalHandler(SIGTERM, SIG_DFL, 0);
|
||||
util::setGlobalSignalHandler(SIGINT, SIG_DFL, 0);
|
||||
util::setGlobalSignalHandler(SIGTERM, SIG_DFL, 0);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
std::stringstream s;
|
||||
std::copy(_tags.begin(), _tags.end(),
|
||||
std::ostream_iterator<std::string>(s, ","));
|
||||
return Util::trim(s.str(), ", ");
|
||||
return util::trim(s.str(), ", ");
|
||||
}
|
||||
|
||||
virtual const std::string& getName() const
|
||||
|
|
|
@ -62,7 +62,7 @@ void NameResolver::resolve(std::deque<std::string>& resolvedAddresses,
|
|||
struct addrinfo* rp;
|
||||
for(rp = res; rp; rp = rp->ai_next) {
|
||||
std::pair<std::string, uint16_t> addressPort
|
||||
= Util::getNumericNameInfo(rp->ai_addr, rp->ai_addrlen);
|
||||
= util::getNumericNameInfo(rp->ai_addr, rp->ai_addrlen);
|
||||
resolvedAddresses.push_back(addressPort.first);
|
||||
}
|
||||
freeaddrinfo(res);
|
||||
|
|
|
@ -89,11 +89,11 @@ void Netrc::parse(const std::string& path)
|
|||
std::string line;
|
||||
STATE state = GET_TOKEN;
|
||||
while(getline(f, line)) {
|
||||
if(Util::startsWith(line, "#")) {
|
||||
if(util::startsWith(line, "#")) {
|
||||
continue;
|
||||
}
|
||||
std::vector<std::string> tokens;
|
||||
split(line, std::back_inserter(tokens), " \t", true);
|
||||
util::split(line, std::back_inserter(tokens), " \t", true);
|
||||
for(std::vector<std::string>::const_iterator iter = tokens.begin();
|
||||
iter != tokens.end(); ++iter) {
|
||||
const std::string& token = *iter;
|
||||
|
|
|
@ -53,12 +53,12 @@ static const std::string C_TRUE("TRUE");
|
|||
static Cookie parseNsCookie(const std::string& nsCookieStr)
|
||||
{
|
||||
std::vector<std::string> vs;
|
||||
split(nsCookieStr, std::back_inserter(vs), "\t", true);
|
||||
util::split(nsCookieStr, std::back_inserter(vs), "\t", true);
|
||||
if(vs.size() < 6 ) {
|
||||
return Cookie();
|
||||
}
|
||||
|
||||
int64_t expireDate = Util::parseLLInt(vs[4]);
|
||||
int64_t expireDate = util::parseLLInt(vs[4]);
|
||||
// TODO assuming time_t is int32_t...
|
||||
if(expireDate > INT32_MAX) {
|
||||
expireDate = INT32_MAX;
|
||||
|
@ -84,7 +84,7 @@ std::deque<Cookie> NsCookieParser::parse(const std::string& filename)
|
|||
std::string line;
|
||||
std::deque<Cookie> cookies;
|
||||
while(getline(s, line)) {
|
||||
if(Util::startsWith(line, A2STR::SHARP_C)) {
|
||||
if(util::startsWith(line, A2STR::SHARP_C)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -115,7 +115,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
|||
SharedHandle<OptionHandler> op(new DefaultOptionHandler
|
||||
(PREF_CONF_PATH,
|
||||
TEXT_CONF_PATH,
|
||||
Util::getHomeDir()+"/.aria2/aria2.conf"));
|
||||
util::getHomeDir()+"/.aria2/aria2.conf"));
|
||||
op->addTag(TAG_ADVANCED);
|
||||
handlers.push_back(op);
|
||||
}
|
||||
|
@ -827,7 +827,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
|||
SharedHandle<DefaultOptionHandler> op(new DefaultOptionHandler
|
||||
(PREF_NETRC_PATH,
|
||||
NO_DESCRIPTION,
|
||||
Util::getHomeDir()+"/.netrc",
|
||||
util::getHomeDir()+"/.netrc",
|
||||
"/PATH/TO/NETRC"));
|
||||
op->hide();
|
||||
handlers.push_back(op);
|
||||
|
@ -1045,7 +1045,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
|||
SharedHandle<OptionHandler> op(new DefaultOptionHandler
|
||||
(PREF_DHT_FILE_PATH,
|
||||
TEXT_DHT_FILE_PATH,
|
||||
Util::getHomeDir()+"/.aria2/dht.dat",
|
||||
util::getHomeDir()+"/.aria2/dht.dat",
|
||||
"/PATH/TO/DHT_DAT"));
|
||||
op->addTag(TAG_BITTORRENT);
|
||||
handlers.push_back(op);
|
||||
|
|
|
@ -159,15 +159,15 @@ public:
|
|||
|
||||
virtual void parseArg(Option& option, const std::string& optarg)
|
||||
{
|
||||
IntSequence seq = Util::parseIntRange(optarg);
|
||||
IntSequence seq = util::parseIntRange(optarg);
|
||||
while(seq.hasNext()) {
|
||||
int32_t v = seq.next();
|
||||
if(v < _min || _max < v) {
|
||||
std::string msg = _optName;
|
||||
strappend(msg, " ", _("must be between %s and %s."));
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(msg.c_str(), Util::itos(_min).c_str(),
|
||||
Util::itos(_max).c_str()).str());
|
||||
(StringFormat(msg.c_str(), util::itos(_min).c_str(),
|
||||
util::itos(_max).c_str()).str());
|
||||
}
|
||||
option.put(_optName, optarg);
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ public:
|
|||
|
||||
virtual std::string createPossibleValuesString() const
|
||||
{
|
||||
return Util::itos(_min)+"-"+Util::itos(_max);
|
||||
return util::itos(_min)+"-"+util::itos(_max);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -198,26 +198,26 @@ public:
|
|||
|
||||
virtual void parseArg(Option& option, const std::string& optarg)
|
||||
{
|
||||
int64_t num = Util::parseLLInt(optarg);
|
||||
int64_t num = util::parseLLInt(optarg);
|
||||
parseArg(option, num);
|
||||
}
|
||||
|
||||
void parseArg(Option& option, int64_t number)
|
||||
{
|
||||
if((_min == -1 || _min <= number) && (_max == -1 || number <= _max)) {
|
||||
option.put(_optName, Util::itos(number));
|
||||
option.put(_optName, util::itos(number));
|
||||
} else {
|
||||
std::string msg = _optName;
|
||||
msg += " ";
|
||||
if(_min == -1 && _max != -1) {
|
||||
msg += StringFormat(_("must be smaller than or equal to %s."),
|
||||
Util::itos(_max).c_str()).str();
|
||||
util::itos(_max).c_str()).str();
|
||||
} else if(_min != -1 && _max != -1) {
|
||||
msg += StringFormat(_("must be between %s and %s."),
|
||||
Util::itos(_min).c_str(), Util::itos(_max).c_str()).str();
|
||||
util::itos(_min).c_str(), util::itos(_max).c_str()).str();
|
||||
} else if(_min != -1 && _max == -1) {
|
||||
msg += StringFormat(_("must be greater than or equal to %s."),
|
||||
Util::itos(_min).c_str()).str();
|
||||
util::itos(_min).c_str()).str();
|
||||
} else {
|
||||
msg += _("must be a number.");
|
||||
}
|
||||
|
@ -231,13 +231,13 @@ public:
|
|||
if(_min == -1) {
|
||||
values += "*";
|
||||
} else {
|
||||
values += Util::itos(_min);
|
||||
values += util::itos(_min);
|
||||
}
|
||||
values += "-";
|
||||
if(_max == -1) {
|
||||
values += "*";
|
||||
} else {
|
||||
values += Util::itos(_max);
|
||||
values += util::itos(_max);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ public:
|
|||
|
||||
virtual void parseArg(Option& option, const std::string& optarg)
|
||||
{
|
||||
int64_t num = Util::getRealSize(optarg);
|
||||
int64_t num = util::getRealSize(optarg);
|
||||
NumberOptionHandler::parseArg(option, num);
|
||||
}
|
||||
};
|
||||
|
@ -400,7 +400,7 @@ public:
|
|||
virtual void parseArg(Option& option, const std::string& optarg)
|
||||
{
|
||||
// See optarg is in the fomrat of "INDEX=PATH"
|
||||
Util::parseIndexPath(optarg);
|
||||
util::parseIndexPath(optarg);
|
||||
std::string value = option.get(_optName);
|
||||
strappend(value, optarg, "\n");
|
||||
option.put(_optName, value);
|
||||
|
@ -492,7 +492,7 @@ public:
|
|||
std::stringstream s;
|
||||
std::copy(_validParamValues.begin(), _validParamValues.end(),
|
||||
std::ostream_iterator<std::string>(s, ","));
|
||||
return Util::trim(s.str(), ", ");
|
||||
return util::trim(s.str(), ", ");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -517,8 +517,8 @@ public:
|
|||
|
||||
virtual void parseArg(Option& option, const std::string& optarg)
|
||||
{
|
||||
std::pair<std::string, std::string> proxy = Util::split(optarg, ":");
|
||||
int32_t port = Util::parseInt(proxy.second);
|
||||
std::pair<std::string, std::string> proxy = util::split(optarg, ":");
|
||||
int32_t port = util::parseInt(proxy.second);
|
||||
if(proxy.first.empty() || proxy.second.empty() ||
|
||||
port <= 0 || 65535 < port) {
|
||||
throw DL_ABORT_EX(_("unrecognized proxy format"));
|
||||
|
@ -530,7 +530,7 @@ public:
|
|||
void setHostAndPort(Option& option, const std::string& hostname, uint16_t port)
|
||||
{
|
||||
option.put(_hostOptionName, hostname);
|
||||
option.put(_portOptionName, Util::uitos(port));
|
||||
option.put(_portOptionName, util::uitos(port));
|
||||
}
|
||||
|
||||
virtual std::string createPossibleValuesString() const
|
||||
|
@ -556,7 +556,7 @@ public:
|
|||
{
|
||||
Request req;
|
||||
std::string url;
|
||||
if(Util::startsWith(optarg, "http://")) {
|
||||
if(util::startsWith(optarg, "http://")) {
|
||||
url = optarg;
|
||||
} else {
|
||||
url = "http://"+optarg;
|
||||
|
|
|
@ -163,10 +163,10 @@ void OptionParser::parse(Option& option, std::istream& is)
|
|||
int32_t linenum = 0;
|
||||
while(getline(is, line)) {
|
||||
++linenum;
|
||||
if(Util::startsWith(line, A2STR::SHARP_C)) {
|
||||
if(util::startsWith(line, A2STR::SHARP_C)) {
|
||||
continue;
|
||||
}
|
||||
std::pair<std::string, std::string> nv = Util::split(line, A2STR::EQUAL_C);
|
||||
std::pair<std::string, std::string> nv = util::split(line, A2STR::EQUAL_C);
|
||||
OptionHandlerHandle handler = getOptionHandlerByName(nv.first);
|
||||
handler->parse(option, nv.second);
|
||||
}
|
||||
|
|
|
@ -91,8 +91,8 @@ PStringDatumHandle ParameterizedStringParser::createSelect(const std::string& sr
|
|||
throw DL_ABORT_EX("Missing '}' in the parameterized string.");
|
||||
}
|
||||
std::deque<std::string> values;
|
||||
split(src.substr(offset, rightParenIndex-offset), std::back_inserter(values),
|
||||
",", true);
|
||||
util::split(src.substr(offset, rightParenIndex-offset),
|
||||
std::back_inserter(values), ",", true);
|
||||
if(values.empty()) {
|
||||
throw DL_ABORT_EX("Empty {} is not allowed.");
|
||||
}
|
||||
|
@ -116,32 +116,32 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src,
|
|||
std::string::size_type colonIndex = loopStr.find(":");
|
||||
if(colonIndex != std::string::npos) {
|
||||
std::string stepStr = loopStr.substr(colonIndex+1);
|
||||
if(Util::isNumber(stepStr)) {
|
||||
step = Util::parseUInt(stepStr);
|
||||
if(util::isNumber(stepStr)) {
|
||||
step = util::parseUInt(stepStr);
|
||||
} else {
|
||||
throw DL_ABORT_EX("A step count must be a positive number.");
|
||||
}
|
||||
loopStr.erase(colonIndex);
|
||||
}
|
||||
std::pair<std::string, std::string> range = Util::split(loopStr, "-");
|
||||
std::pair<std::string, std::string> range = util::split(loopStr, "-");
|
||||
if(range.first.empty() || range.second.empty()) {
|
||||
throw DL_ABORT_EX("Loop range missing.");
|
||||
}
|
||||
NumberDecoratorHandle nd;
|
||||
unsigned int start;
|
||||
unsigned int end;
|
||||
if(Util::isNumber(range.first) && Util::isNumber(range.second)) {
|
||||
if(util::isNumber(range.first) && util::isNumber(range.second)) {
|
||||
nd.reset(new FixedWidthNumberDecorator(range.first.size()));
|
||||
start = Util::parseUInt(range.first);
|
||||
end = Util::parseUInt(range.second);
|
||||
} else if(Util::isLowercase(range.first) && Util::isLowercase(range.second)) {
|
||||
start = util::parseUInt(range.first);
|
||||
end = util::parseUInt(range.second);
|
||||
} else if(util::isLowercase(range.first) && util::isLowercase(range.second)) {
|
||||
nd.reset(new AlphaNumberDecorator(range.first.size()));
|
||||
start = Util::alphaToNum(range.first);
|
||||
end = Util::alphaToNum(range.second);
|
||||
} else if(Util::isUppercase(range.first) && Util::isUppercase(range.second)) {
|
||||
start = util::alphaToNum(range.first);
|
||||
end = util::alphaToNum(range.second);
|
||||
} else if(util::isUppercase(range.first) && util::isUppercase(range.second)) {
|
||||
nd.reset(new AlphaNumberDecorator(range.first.size(), true));
|
||||
start = Util::alphaToNum(range.first);
|
||||
end = Util::alphaToNum(range.second);
|
||||
start = util::alphaToNum(range.first);
|
||||
end = util::alphaToNum(range.second);
|
||||
} else {
|
||||
throw DL_ABORT_EX("Invalid loop range.");
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
|
|||
memset(_peerId, 0, PEER_ID_LENGTH);
|
||||
resetStatus();
|
||||
std::string idSeed = ipaddr;
|
||||
strappend(idSeed, ":", Util::uitos(port));
|
||||
strappend(idSeed, ":", util::uitos(port));
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
id = MessageDigestHelper::digestString(MessageDigestContext::SHA1, idSeed);
|
||||
#else
|
||||
|
|
|
@ -102,7 +102,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
|||
if(downloadContext.isNull() || !btRuntime->ready()) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("Unknown info hash %s",
|
||||
Util::toHex(infoHash).c_str()).str());
|
||||
util::toHex(infoHash).c_str()).str());
|
||||
}
|
||||
TransferStat tstat =
|
||||
downloadContext->getOwnerRequestGroup()->calculateStat();
|
||||
|
|
|
@ -195,8 +195,8 @@ bool Piece::getAllMissingBlockIndexes
|
|||
}
|
||||
|
||||
std::string Piece::toString() const {
|
||||
return strconcat("piece: index=", Util::itos(index),
|
||||
", length=", Util::itos(length));
|
||||
return strconcat("piece: index=", util::itos(index),
|
||||
", length=", util::itos(length));
|
||||
}
|
||||
|
||||
void Piece::reconfigure(size_t length)
|
||||
|
@ -256,7 +256,7 @@ std::string Piece::getHashString()
|
|||
if(_mdctx.isNull()) {
|
||||
return A2STR::NIL;
|
||||
} else {
|
||||
return Util::toHex(_mdctx->digestFinal());
|
||||
return util::toHex(_mdctx->digestFinal());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,9 +80,9 @@ size_t RangeBtMessage::getMessageLength()
|
|||
|
||||
std::string RangeBtMessage::toString() const
|
||||
{
|
||||
return strconcat(getName(), " index=", Util::uitos(_index),
|
||||
", begin=", Util::uitos(_begin),
|
||||
", length=", Util::uitos(_length));
|
||||
return strconcat(getName(), " index=", util::uitos(_index),
|
||||
", begin=", util::uitos(_begin),
|
||||
", length=", util::uitos(_length));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -101,7 +101,7 @@ static std::string urlencode(const std::string& src)
|
|||
for(int index = src.size()-1; index >= 0; --index) {
|
||||
const unsigned char c = result[index];
|
||||
// '/' is not urlencoded because src is expected to be a path.
|
||||
if(!Util::inRFC3986ReservedChars(c) && !Util::inRFC3986UnreservedChars(c)) {
|
||||
if(!util::inRFC3986ReservedChars(c) && !util::inRFC3986UnreservedChars(c)) {
|
||||
if(c == '%') {
|
||||
if(!isHexNumber(result[index+1]) || !isHexNumber(result[index+2])) {
|
||||
result.replace(index, 1, "%25");
|
||||
|
@ -139,7 +139,7 @@ bool Request::redirectUrl(const std::string& url) {
|
|||
if(url.find("://") == std::string::npos) {
|
||||
// rfc2616 requires absolute URI should be provided by Location header
|
||||
// field, but some servers don't obey this rule.
|
||||
if(Util::startsWith(url, "/")) {
|
||||
if(util::startsWith(url, "/")) {
|
||||
// abosulute path
|
||||
return parseUrl(strconcat(protocol, "://", host, url));
|
||||
} else {
|
||||
|
@ -190,15 +190,15 @@ bool Request::parseUrl(const std::string& url) {
|
|||
if(atmarkp != std::string::npos) {
|
||||
std::string authPart = hostPart.substr(0, atmarkp);
|
||||
std::pair<std::string, std::string> userPass =
|
||||
Util::split(authPart, A2STR::COLON_C);
|
||||
_username = Util::urldecode(userPass.first);
|
||||
_password = Util::urldecode(userPass.second);
|
||||
util::split(authPart, A2STR::COLON_C);
|
||||
_username = util::urldecode(userPass.first);
|
||||
_password = util::urldecode(userPass.second);
|
||||
hostPart.erase(0, atmarkp+1);
|
||||
}
|
||||
{
|
||||
std::string::size_type colonpos;
|
||||
// Detect IPv6 literal address in square brackets
|
||||
if(Util::startsWith(hostPart, "[")) {
|
||||
if(util::startsWith(hostPart, "[")) {
|
||||
std::string::size_type rbracketpos = hostPart.find("]");
|
||||
if(rbracketpos == std::string::npos) {
|
||||
return false;
|
||||
|
@ -215,7 +215,7 @@ bool Request::parseUrl(const std::string& url) {
|
|||
port = defPort;
|
||||
} else {
|
||||
try {
|
||||
unsigned int tempPort = Util::parseUInt(hostPart.substr(colonpos+1));
|
||||
unsigned int tempPort = util::parseUInt(hostPart.substr(colonpos+1));
|
||||
if(65535 < tempPort) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
|
|||
throw DOWNLOAD_FAILURE_EXCEPTION
|
||||
(StringFormat
|
||||
("InfoHash %s is already registered.",
|
||||
Util::toHex(torrentAttrs[bittorrent::INFO_HASH].s()).c_str()).str());
|
||||
util::toHex(torrentAttrs[bittorrent::INFO_HASH].s()).c_str()).str());
|
||||
}
|
||||
|
||||
if(e->_requestGroupMan->isSameFileBeingDownloaded(this)) {
|
||||
|
@ -280,8 +280,8 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
|
|||
// truncate the file to _downloadContext->getTotalLength()
|
||||
_logger->debug("File size not match. File is opened in writable mode."
|
||||
" Expected:%s Actual:%s",
|
||||
Util::uitos(_downloadContext->getTotalLength()).c_str(),
|
||||
Util::uitos(actualFileSize).c_str());
|
||||
util::uitos(_downloadContext->getTotalLength()).c_str(),
|
||||
util::uitos(actualFileSize).c_str());
|
||||
}
|
||||
}
|
||||
// Call Load, Save and file allocation command here
|
||||
|
@ -568,7 +568,7 @@ bool RequestGroup::tryAutoFileRenaming()
|
|||
return false;
|
||||
}
|
||||
for(unsigned int i = 1; i < 10000; ++i) {
|
||||
File newfile(strconcat(filepath, ".", Util::uitos(i)));
|
||||
File newfile(strconcat(filepath, ".", util::uitos(i)));
|
||||
File ctrlfile(newfile.getPath()+DefaultBtProgressInfoFile::getSuffix());
|
||||
if(!newfile.exists() || (newfile.exists() && ctrlfile.exists())) {
|
||||
_downloadContext->getFirstFileEntry()->setPath(newfile.getPath());
|
||||
|
@ -666,8 +666,8 @@ void RequestGroup::validateTotalLength(uint64_t expectedTotalLength,
|
|||
if(expectedTotalLength != actualTotalLength) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(EX_SIZE_MISMATCH,
|
||||
Util::itos(expectedTotalLength, true).c_str(),
|
||||
Util::itos(actualTotalLength, true).c_str()).str());
|
||||
util::itos(expectedTotalLength, true).c_str(),
|
||||
util::itos(actualTotalLength, true).c_str()).str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -942,8 +942,8 @@ void RequestGroup::reportDownloadFinished()
|
|||
double shareRatio = ((stat.getAllTimeUploadLength()*10)/getCompletedLength())/10.0;
|
||||
_logger->notice(MSG_SHARE_RATIO_REPORT,
|
||||
shareRatio,
|
||||
Util::abbrevSize(stat.getAllTimeUploadLength()).c_str(),
|
||||
Util::abbrevSize(getCompletedLength()).c_str());
|
||||
util::abbrevSize(stat.getAllTimeUploadLength()).c_str(),
|
||||
util::abbrevSize(getCompletedLength()).c_str());
|
||||
}
|
||||
#endif // ENABLE_BITTORRENT
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ static void executeHook(const std::string& command, int gid)
|
|||
LogFactory::getInstance()->error("fork() failed."
|
||||
" Cannot execute user command.");
|
||||
} else if(cpid == 0) {
|
||||
execl(command.c_str(), command.c_str(), Util::itos(gid).c_str(), (char*)0);
|
||||
execl(command.c_str(), command.c_str(), util::itos(gid).c_str(), (char*)0);
|
||||
perror(("Could not execute user command: "+command).c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ static void executeHook(const std::string& command, int gid)
|
|||
memset(&pi, 0, sizeof (pi));
|
||||
|
||||
std::string cmdline = command;
|
||||
strappend(cmdline, " ", Util::itos(gid));
|
||||
strappend(cmdline, " ", util::itos(gid));
|
||||
|
||||
DWORD rc = CreateProcess(
|
||||
NULL,
|
||||
|
@ -623,7 +623,7 @@ std::string RequestGroupMan::formatDownloadResult(const std::string& status, con
|
|||
<< std::setw(4) << status << "|"
|
||||
<< std::setw(11);
|
||||
if(downloadResult->sessionTime > 0) {
|
||||
o << Util::abbrevSize
|
||||
o << util::abbrevSize
|
||||
(downloadResult->sessionDownloadLength*1000/downloadResult->sessionTime)+
|
||||
"B/s";
|
||||
} else {
|
||||
|
|
|
@ -98,18 +98,18 @@ bool ServerStatMan::load(std::istream& in)
|
|||
|
||||
std::string line;
|
||||
while(getline(in, line)) {
|
||||
Util::trimSelf(line);
|
||||
util::trimSelf(line);
|
||||
if(line.empty()) {
|
||||
continue;
|
||||
}
|
||||
std::vector<std::string> items;
|
||||
split(line, std::back_inserter(items), ",");
|
||||
util::split(line, std::back_inserter(items), ",");
|
||||
std::map<std::string, std::string> m;
|
||||
for(std::vector<std::string>::const_iterator i = items.begin();
|
||||
i != items.end(); ++i) {
|
||||
std::pair<std::string, std::string> p = Util::split(*i, "=");
|
||||
Util::trimSelf(p.first);
|
||||
Util::trimSelf(p.second);
|
||||
std::pair<std::string, std::string> p = util::split(*i, "=");
|
||||
util::trimSelf(p.first);
|
||||
util::trimSelf(p.second);
|
||||
m[p.first] = p.second;
|
||||
}
|
||||
if(m[S_HOST].empty() || m[S_PROTOCOL].empty()) {
|
||||
|
@ -117,20 +117,20 @@ bool ServerStatMan::load(std::istream& in)
|
|||
}
|
||||
SharedHandle<ServerStat> sstat(new ServerStat(m[S_HOST], m[S_PROTOCOL]));
|
||||
try {
|
||||
sstat->setDownloadSpeed(Util::parseUInt(m[S_DL_SPEED]));
|
||||
sstat->setDownloadSpeed(util::parseUInt(m[S_DL_SPEED]));
|
||||
// Old serverstat file doesn't contains SC_AVG_SPEED
|
||||
if(m.find(S_SC_AVG_SPEED) != m.end()) {
|
||||
sstat->setSingleConnectionAvgSpeed(Util::parseUInt(m[S_SC_AVG_SPEED]));
|
||||
sstat->setSingleConnectionAvgSpeed(util::parseUInt(m[S_SC_AVG_SPEED]));
|
||||
}
|
||||
// Old serverstat file doesn't contains MC_AVG_SPEED
|
||||
if(m.find(S_MC_AVG_SPEED) != m.end()) {
|
||||
sstat->setMultiConnectionAvgSpeed(Util::parseUInt(m[S_MC_AVG_SPEED]));
|
||||
sstat->setMultiConnectionAvgSpeed(util::parseUInt(m[S_MC_AVG_SPEED]));
|
||||
}
|
||||
// Old serverstat file doesn't contains COUNTER_SPEED
|
||||
if(m.find(S_COUNTER) != m.end()) {
|
||||
sstat->setCounter(Util::parseUInt(m[S_COUNTER]));
|
||||
sstat->setCounter(util::parseUInt(m[S_COUNTER]));
|
||||
}
|
||||
sstat->setLastUpdated(Time(Util::parseInt(m[S_LAST_UPDATED])));
|
||||
sstat->setLastUpdated(Time(util::parseInt(m[S_LAST_UPDATED])));
|
||||
sstat->setStatus(m[S_STATUS]);
|
||||
add(sstat);
|
||||
} catch(RecoverableException& e) {
|
||||
|
|
|
@ -69,7 +69,7 @@ void SimpleLogger::writeLog
|
|||
writeHeader(o, datestr, logLevelLabel);
|
||||
{
|
||||
char buf[1024];
|
||||
std::string body = Util::replace(msg, A2STR::CR_C, A2STR::NIL);
|
||||
std::string body = util::replace(msg, A2STR::CR_C, A2STR::NIL);
|
||||
body += A2STR::LF_C;
|
||||
if(vsnprintf(buf, sizeof(buf), body.c_str(), ap) < 0) {
|
||||
o << "SimpleLogger error, failed to format message.\n";
|
||||
|
|
|
@ -63,7 +63,7 @@ SingleFileAllocationIterator::~SingleFileAllocationIterator()
|
|||
void SingleFileAllocationIterator::init()
|
||||
{
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
_buffer = (unsigned char*)Util::allocateAlignedMemory(ALIGNMENT, BUFSIZE);
|
||||
_buffer = (unsigned char*)util::allocateAlignedMemory(ALIGNMENT, BUFSIZE);
|
||||
#else
|
||||
_buffer = new unsigned char[BUFSIZE];
|
||||
#endif // HAVE_POSIX_MEMALIGN
|
||||
|
|
|
@ -226,7 +226,7 @@ void SocketCore::getAddrInfo(std::pair<std::string, uint16_t>& addrinfo) const
|
|||
if(getsockname(sockfd, addrp, &len) == -1) {
|
||||
throw DL_ABORT_EX(StringFormat(EX_SOCKET_GET_NAME, errorMsg()).str());
|
||||
}
|
||||
addrinfo = Util::getNumericNameInfo(addrp, len);
|
||||
addrinfo = util::getNumericNameInfo(addrp, len);
|
||||
}
|
||||
|
||||
void SocketCore::getPeerInfo(std::pair<std::string, uint16_t>& peerinfo) const
|
||||
|
@ -237,7 +237,7 @@ void SocketCore::getPeerInfo(std::pair<std::string, uint16_t>& peerinfo) const
|
|||
if(getpeername(sockfd, addrp, &len) == -1) {
|
||||
throw DL_ABORT_EX(StringFormat(EX_SOCKET_GET_NAME, errorMsg()).str());
|
||||
}
|
||||
peerinfo = Util::getNumericNameInfo(addrp, len);
|
||||
peerinfo = util::getNumericNameInfo(addrp, len);
|
||||
}
|
||||
|
||||
void SocketCore::establishConnection(const std::string& host, uint16_t port)
|
||||
|
@ -1029,7 +1029,7 @@ ssize_t SocketCore::readDataFrom(char* data, size_t len,
|
|||
throw DL_RETRY_EX(StringFormat(EX_SOCKET_RECV, errorMsg()).str());
|
||||
}
|
||||
} else {
|
||||
sender = Util::getNumericNameInfo(addrp, sockaddrlen);
|
||||
sender = util::getNumericNameInfo(addrp, sockaddrlen);
|
||||
}
|
||||
|
||||
return r;
|
||||
|
|
|
@ -65,7 +65,7 @@ static int cookieRowMapper(void* data, int rowIndex,
|
|||
char** values, char** names)
|
||||
{
|
||||
try {
|
||||
int64_t expireDate = Util::parseLLInt(toString(values[3]));
|
||||
int64_t expireDate = util::parseLLInt(toString(values[3]));
|
||||
// TODO assuming time_t is int32_t...
|
||||
if(expireDate > INT32_MAX) {
|
||||
expireDate = INT32_MAX;
|
||||
|
|
|
@ -76,7 +76,7 @@ Time& Time::operator=(const Time& time)
|
|||
|
||||
bool Time::operator<(const Time& time) const
|
||||
{
|
||||
return Util::difftv(time.tv, tv) > 0;
|
||||
return util::difftv(time.tv, tv) > 0;
|
||||
}
|
||||
|
||||
void Time::reset() {
|
||||
|
@ -99,36 +99,36 @@ bool Time::elapsed(time_t sec) const {
|
|||
return true;
|
||||
} else if(tv.tv_sec+sec == now) {
|
||||
return
|
||||
Util::difftv(getCurrentTime(), tv) >= static_cast<int64_t>(sec)*1000000;
|
||||
util::difftv(getCurrentTime(), tv) >= static_cast<int64_t>(sec)*1000000;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Time::elapsedInMillis(int64_t millis) const {
|
||||
return Util::difftv(getCurrentTime(), tv)/1000 >= millis;
|
||||
return util::difftv(getCurrentTime(), tv)/1000 >= millis;
|
||||
}
|
||||
|
||||
bool Time::isNewer(const Time& time) const {
|
||||
return Util::difftv(this->tv, time.tv) > 0;
|
||||
return util::difftv(this->tv, time.tv) > 0;
|
||||
}
|
||||
|
||||
time_t Time::difference() const {
|
||||
return Util::difftvsec(getCurrentTime(), tv);
|
||||
return util::difftvsec(getCurrentTime(), tv);
|
||||
}
|
||||
|
||||
time_t Time::difference(const struct timeval& now) const
|
||||
{
|
||||
return Util::difftvsec(now, tv);
|
||||
return util::difftvsec(now, tv);
|
||||
}
|
||||
|
||||
int64_t Time::differenceInMillis() const {
|
||||
return Util::difftv(getCurrentTime(), tv)/1000;
|
||||
return util::difftv(getCurrentTime(), tv)/1000;
|
||||
}
|
||||
|
||||
int64_t Time::differenceInMillis(const struct timeval& now) const
|
||||
{
|
||||
return Util::difftv(now, tv)/1000;
|
||||
return util::difftv(now, tv)/1000;
|
||||
}
|
||||
|
||||
bool Time::isZero() const
|
||||
|
|
|
@ -87,8 +87,8 @@ UTPexExtensionMessage::createCompactPeerListAndFlag(const Peers& peers)
|
|||
|
||||
std::string UTPexExtensionMessage::toString() const
|
||||
{
|
||||
return strconcat("ut_pex added=", Util::uitos(_freshPeers.size()),
|
||||
", dropped=", Util::uitos(_droppedPeers.size()));
|
||||
return strconcat("ut_pex added=", util::uitos(_freshPeers.size()),
|
||||
", dropped=", util::uitos(_droppedPeers.size()));
|
||||
}
|
||||
|
||||
void UTPexExtensionMessage::doReceivedAction()
|
||||
|
|
|
@ -55,7 +55,7 @@ void UriListParser::getOptions(Option& op)
|
|||
{
|
||||
std::stringstream ss;
|
||||
while(getline(_in, _line)) {
|
||||
if(Util::startsWith(_line, " ")) {
|
||||
if(util::startsWith(_line, " ")) {
|
||||
ss << _line << "\n";
|
||||
} else {
|
||||
break;
|
||||
|
@ -73,8 +73,8 @@ void UriListParser::parseNext(std::deque<std::string>& uris, Option& op)
|
|||
return;
|
||||
}
|
||||
do {
|
||||
if(!Util::trim(_line).empty()) {
|
||||
split(_line, std::back_inserter(uris), "\t", true);
|
||||
if(!util::trim(_line).empty()) {
|
||||
util::split(_line, std::back_inserter(uris), "\t", true);
|
||||
getOptions(op);
|
||||
return;
|
||||
}
|
||||
|
|
149
src/Util.cc
149
src/Util.cc
|
@ -83,16 +83,18 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
const std::string Util::DEFAULT_TRIM_CHARSET("\r\n\t ");
|
||||
namespace util {
|
||||
|
||||
std::string Util::trim(const std::string& src, const std::string& trimCharset)
|
||||
const std::string DEFAULT_TRIM_CHARSET("\r\n\t ");
|
||||
|
||||
std::string trim(const std::string& src, const std::string& trimCharset)
|
||||
{
|
||||
std::string temp(src);
|
||||
trimSelf(temp, trimCharset);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void Util::trimSelf(std::string& str, const std::string& trimCharset)
|
||||
void trimSelf(std::string& str, const std::string& trimCharset)
|
||||
{
|
||||
std::string::size_type first = str.find_first_not_of(trimCharset);
|
||||
if(first == std::string::npos) {
|
||||
|
@ -104,7 +106,7 @@ void Util::trimSelf(std::string& str, const std::string& trimCharset)
|
|||
}
|
||||
}
|
||||
|
||||
void Util::split(std::pair<std::string, std::string>& hp, const std::string& src, char delim)
|
||||
void split(std::pair<std::string, std::string>& hp, const std::string& src, char delim)
|
||||
{
|
||||
hp.first = A2STR::NIL;
|
||||
hp.second = A2STR::NIL;
|
||||
|
@ -118,7 +120,7 @@ void Util::split(std::pair<std::string, std::string>& hp, const std::string& src
|
|||
}
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> Util::split(const std::string& src, const std::string& delims)
|
||||
std::pair<std::string, std::string> split(const std::string& src, const std::string& delims)
|
||||
{
|
||||
std::pair<std::string, std::string> hp;
|
||||
hp.first = A2STR::NIL;
|
||||
|
@ -134,7 +136,7 @@ std::pair<std::string, std::string> Util::split(const std::string& src, const st
|
|||
return hp;
|
||||
}
|
||||
|
||||
int64_t Util::difftv(struct timeval tv1, struct timeval tv2) {
|
||||
int64_t difftv(struct timeval tv1, struct timeval tv2) {
|
||||
if((tv1.tv_sec < tv2.tv_sec) ||
|
||||
((tv1.tv_sec == tv2.tv_sec) && (tv1.tv_usec < tv2.tv_usec))) {
|
||||
return 0;
|
||||
|
@ -143,14 +145,14 @@ int64_t Util::difftv(struct timeval tv1, struct timeval tv2) {
|
|||
tv1.tv_usec-tv2.tv_usec);
|
||||
}
|
||||
|
||||
int32_t Util::difftvsec(struct timeval tv1, struct timeval tv2) {
|
||||
int32_t difftvsec(struct timeval tv1, struct timeval tv2) {
|
||||
if(tv1.tv_sec < tv2.tv_sec) {
|
||||
return 0;
|
||||
}
|
||||
return tv1.tv_sec-tv2.tv_sec;
|
||||
}
|
||||
|
||||
bool Util::startsWith(const std::string& target, const std::string& part) {
|
||||
bool startsWith(const std::string& target, const std::string& part) {
|
||||
if(target.size() < part.size()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -164,7 +166,7 @@ bool Util::startsWith(const std::string& target, const std::string& part) {
|
|||
}
|
||||
}
|
||||
|
||||
bool Util::endsWith(const std::string& target, const std::string& part) {
|
||||
bool endsWith(const std::string& target, const std::string& part) {
|
||||
if(target.size() < part.size()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -178,7 +180,7 @@ bool Util::endsWith(const std::string& target, const std::string& part) {
|
|||
}
|
||||
}
|
||||
|
||||
std::string Util::replace(const std::string& target, const std::string& oldstr, const std::string& newstr) {
|
||||
std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr) {
|
||||
if(target.empty() || oldstr.empty()) {
|
||||
return target;
|
||||
}
|
||||
|
@ -196,7 +198,7 @@ std::string Util::replace(const std::string& target, const std::string& oldstr,
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Util::inRFC3986ReservedChars(const char c)
|
||||
bool inRFC3986ReservedChars(const char c)
|
||||
{
|
||||
static const char reserved[] = {
|
||||
':' , '/' , '?' , '#' , '[' , ']' , '@',
|
||||
|
@ -206,7 +208,7 @@ bool Util::inRFC3986ReservedChars(const char c)
|
|||
&reserved[arrayLength(reserved)];
|
||||
}
|
||||
|
||||
bool Util::inRFC3986UnreservedChars(const char c)
|
||||
bool inRFC3986UnreservedChars(const char c)
|
||||
{
|
||||
static const char unreserved[] = { '-', '.', '_', '~' };
|
||||
return
|
||||
|
@ -218,7 +220,7 @@ bool Util::inRFC3986UnreservedChars(const char c)
|
|||
&unreserved[arrayLength(unreserved)];
|
||||
}
|
||||
|
||||
std::string Util::urlencode(const unsigned char* target, size_t len) {
|
||||
std::string urlencode(const unsigned char* target, size_t len) {
|
||||
std::string dest;
|
||||
for(size_t i = 0; i < len; ++i) {
|
||||
if(!inRFC3986UnreservedChars(target[i])) {
|
||||
|
@ -230,7 +232,12 @@ std::string Util::urlencode(const unsigned char* target, size_t len) {
|
|||
return dest;
|
||||
}
|
||||
|
||||
std::string Util::torrentUrlencode(const unsigned char* target, size_t len) {
|
||||
std::string urlencode(const std::string& target)
|
||||
{
|
||||
return urlencode((const unsigned char*)target.c_str(), target.size());
|
||||
}
|
||||
|
||||
std::string torrentUrlencode(const unsigned char* target, size_t len) {
|
||||
std::string dest;
|
||||
for(size_t i = 0; i < len; ++i) {
|
||||
if(('0' <= target[i] && target[i] <= '9') ||
|
||||
|
@ -244,14 +251,20 @@ std::string Util::torrentUrlencode(const unsigned char* target, size_t len) {
|
|||
return dest;
|
||||
}
|
||||
|
||||
std::string Util::urldecode(const std::string& target) {
|
||||
std::string torrentUrlencode(const std::string& target)
|
||||
{
|
||||
return torrentUrlencode
|
||||
(reinterpret_cast<const unsigned char*>(target.c_str()), target.size());
|
||||
}
|
||||
|
||||
std::string urldecode(const std::string& target) {
|
||||
std::string result;
|
||||
for(std::string::const_iterator itr = target.begin();
|
||||
itr != target.end(); ++itr) {
|
||||
if(*itr == '%') {
|
||||
if(itr+1 != target.end() && itr+2 != target.end() &&
|
||||
isxdigit(*(itr+1)) && isxdigit(*(itr+2))) {
|
||||
result += Util::parseInt(std::string(itr+1, itr+3), 16);
|
||||
result += parseInt(std::string(itr+1, itr+3), 16);
|
||||
itr += 2;
|
||||
} else {
|
||||
result += *itr;
|
||||
|
@ -263,7 +276,7 @@ std::string Util::urldecode(const std::string& target) {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string Util::toHex(const unsigned char* src, size_t len) {
|
||||
std::string toHex(const unsigned char* src, size_t len) {
|
||||
char* temp = new char[len*2+1];
|
||||
for(size_t i = 0; i < len; ++i) {
|
||||
sprintf(temp+i*2, "%02x", src[i]);
|
||||
|
@ -274,12 +287,22 @@ std::string Util::toHex(const unsigned char* src, size_t len) {
|
|||
return hex;
|
||||
}
|
||||
|
||||
FILE* Util::openFile(const std::string& filename, const std::string& mode) {
|
||||
std::string toHex(const char* src, size_t len)
|
||||
{
|
||||
return toHex(reinterpret_cast<const unsigned char*>(src), len);
|
||||
}
|
||||
|
||||
std::string toHex(const std::string& src)
|
||||
{
|
||||
return toHex(reinterpret_cast<const unsigned char*>(src.c_str()), src.size());
|
||||
}
|
||||
|
||||
FILE* openFile(const std::string& filename, const std::string& mode) {
|
||||
FILE* file = fopen(filename.c_str(), mode.c_str());
|
||||
return file;
|
||||
}
|
||||
|
||||
bool Util::isPowerOf(int num, int base) {
|
||||
bool isPowerOf(int num, int base) {
|
||||
if(base <= 0) { return false; }
|
||||
if(base == 1) { return true; }
|
||||
|
||||
|
@ -292,7 +315,7 @@ bool Util::isPowerOf(int num, int base) {
|
|||
return false;
|
||||
}
|
||||
|
||||
std::string Util::secfmt(time_t sec) {
|
||||
std::string secfmt(time_t sec) {
|
||||
std::string str;
|
||||
if(sec >= 3600) {
|
||||
str = itos(sec/3600);
|
||||
|
@ -325,9 +348,9 @@ int getNum(const char* buf, int offset, size_t length) {
|
|||
return x;
|
||||
}
|
||||
|
||||
int32_t Util::parseInt(const std::string& s, int32_t base)
|
||||
int32_t parseInt(const std::string& s, int32_t base)
|
||||
{
|
||||
std::string trimed = Util::trim(s);
|
||||
std::string trimed = trim(s);
|
||||
if(trimed.empty()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
||||
"empty string").str());
|
||||
|
@ -347,9 +370,9 @@ int32_t Util::parseInt(const std::string& s, int32_t base)
|
|||
return v;
|
||||
}
|
||||
|
||||
uint32_t Util::parseUInt(const std::string& s, int base)
|
||||
uint32_t parseUInt(const std::string& s, int base)
|
||||
{
|
||||
std::string trimed = Util::trim(s);
|
||||
std::string trimed = trim(s);
|
||||
if(trimed.empty()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
||||
"empty string").str());
|
||||
|
@ -372,9 +395,9 @@ uint32_t Util::parseUInt(const std::string& s, int base)
|
|||
return v;
|
||||
}
|
||||
|
||||
int64_t Util::parseLLInt(const std::string& s, int32_t base)
|
||||
int64_t parseLLInt(const std::string& s, int32_t base)
|
||||
{
|
||||
std::string trimed = Util::trim(s);
|
||||
std::string trimed = trim(s);
|
||||
if(trimed.empty()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
||||
"empty string").str());
|
||||
|
@ -392,9 +415,9 @@ int64_t Util::parseLLInt(const std::string& s, int32_t base)
|
|||
return v;
|
||||
}
|
||||
|
||||
uint64_t Util::parseULLInt(const std::string& s, int base)
|
||||
uint64_t parseULLInt(const std::string& s, int base)
|
||||
{
|
||||
std::string trimed = Util::trim(s);
|
||||
std::string trimed = trim(s);
|
||||
if(trimed.empty()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
||||
"empty string").str());
|
||||
|
@ -417,34 +440,34 @@ uint64_t Util::parseULLInt(const std::string& s, int base)
|
|||
return v;
|
||||
}
|
||||
|
||||
IntSequence Util::parseIntRange(const std::string& src)
|
||||
IntSequence parseIntRange(const std::string& src)
|
||||
{
|
||||
IntSequence::Values values;
|
||||
std::string temp = src;
|
||||
while(temp.size()) {
|
||||
std::pair<std::string, std::string> p = Util::split(temp, ",");
|
||||
std::pair<std::string, std::string> p = split(temp, ",");
|
||||
temp = p.second;
|
||||
if(p.first.empty()) {
|
||||
continue;
|
||||
}
|
||||
if(p.first.find("-") == std::string::npos) {
|
||||
int32_t v = Util::parseInt(p.first.c_str());
|
||||
int32_t v = parseInt(p.first.c_str());
|
||||
values.push_back(IntSequence::Value(v, v+1));
|
||||
} else {
|
||||
std::pair<std::string, std::string> vp = Util::split(p.first.c_str(), "-");
|
||||
std::pair<std::string, std::string> vp = split(p.first.c_str(), "-");
|
||||
if(vp.first.empty() || vp.second.empty()) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(MSG_INCOMPLETE_RANGE, p.first.c_str()).str());
|
||||
}
|
||||
int32_t v1 = Util::parseInt(vp.first.c_str());
|
||||
int32_t v2 = Util::parseInt(vp.second.c_str());
|
||||
int32_t v1 = parseInt(vp.first.c_str());
|
||||
int32_t v2 = parseInt(vp.second.c_str());
|
||||
values.push_back(IntSequence::Value(v1, v2+1));
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
std::string Util::getContentDispositionFilename(const std::string& header) {
|
||||
std::string getContentDispositionFilename(const std::string& header) {
|
||||
static const std::string keyName = "filename=";
|
||||
std::string::size_type attributesp = header.find(keyName);
|
||||
if(attributesp == std::string::npos) {
|
||||
|
@ -476,7 +499,7 @@ std::string Util::getContentDispositionFilename(const std::string& header) {
|
|||
}
|
||||
}
|
||||
|
||||
std::string Util::randomAlpha(size_t length, const RandomizerHandle& randomizer) {
|
||||
std::string randomAlpha(size_t length, const RandomizerHandle& randomizer) {
|
||||
static const char *random_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
std::string str;
|
||||
for(size_t i = 0; i < length; ++i) {
|
||||
|
@ -486,19 +509,19 @@ std::string Util::randomAlpha(size_t length, const RandomizerHandle& randomizer)
|
|||
return str;
|
||||
}
|
||||
|
||||
std::string Util::toUpper(const std::string& src) {
|
||||
std::string toUpper(const std::string& src) {
|
||||
std::string temp = src;
|
||||
std::transform(temp.begin(), temp.end(), temp.begin(), ::toupper);
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::string Util::toLower(const std::string& src) {
|
||||
std::string toLower(const std::string& src) {
|
||||
std::string temp = src;
|
||||
std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool Util::isNumbersAndDotsNotation(const std::string& name) {
|
||||
bool isNumbersAndDotsNotation(const std::string& name) {
|
||||
struct sockaddr_in sockaddr;
|
||||
if(inet_aton(name.c_str(), &sockaddr.sin_addr)) {
|
||||
return true;
|
||||
|
@ -507,7 +530,7 @@ bool Util::isNumbersAndDotsNotation(const std::string& name) {
|
|||
}
|
||||
}
|
||||
|
||||
void Util::setGlobalSignalHandler(int sig, void (*handler)(int), int flags) {
|
||||
void setGlobalSignalHandler(int sig, void (*handler)(int), int flags) {
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction sigact;
|
||||
sigact.sa_handler = handler;
|
||||
|
@ -519,7 +542,7 @@ void Util::setGlobalSignalHandler(int sig, void (*handler)(int), int flags) {
|
|||
#endif // HAVE_SIGACTION
|
||||
}
|
||||
|
||||
std::string Util::getHomeDir()
|
||||
std::string getHomeDir()
|
||||
{
|
||||
const char* p = getenv("HOME");
|
||||
if(p) {
|
||||
|
@ -529,7 +552,7 @@ std::string Util::getHomeDir()
|
|||
}
|
||||
}
|
||||
|
||||
int64_t Util::getRealSize(const std::string& sizeWithUnit)
|
||||
int64_t getRealSize(const std::string& sizeWithUnit)
|
||||
{
|
||||
std::string::size_type p = sizeWithUnit.find_first_of("KM");
|
||||
std::string size;
|
||||
|
@ -544,7 +567,7 @@ int64_t Util::getRealSize(const std::string& sizeWithUnit)
|
|||
}
|
||||
size = sizeWithUnit.substr(0, p);
|
||||
}
|
||||
int64_t v = Util::parseLLInt(size);
|
||||
int64_t v = parseLLInt(size);
|
||||
|
||||
if(v < 0) {
|
||||
throw DL_ABORT_EX
|
||||
|
@ -556,10 +579,10 @@ int64_t Util::getRealSize(const std::string& sizeWithUnit)
|
|||
return v*mult;
|
||||
}
|
||||
|
||||
std::string Util::abbrevSize(int64_t size)
|
||||
std::string abbrevSize(int64_t size)
|
||||
{
|
||||
if(size < 1024) {
|
||||
return Util::itos(size, true);
|
||||
return itos(size, true);
|
||||
}
|
||||
char units[] = { 'K', 'M' };
|
||||
size_t numUnit = sizeof(units)/sizeof(char);
|
||||
|
@ -570,15 +593,15 @@ std::string Util::abbrevSize(int64_t size)
|
|||
r = size&0x3ff;
|
||||
size >>= 10;
|
||||
}
|
||||
std::string result = Util::itos(size, true);
|
||||
std::string result = itos(size, true);
|
||||
result += ".";
|
||||
result += Util::itos(r*10/1024);
|
||||
result += itos(r*10/1024);
|
||||
result += units[i];
|
||||
result += "i";
|
||||
return result;
|
||||
}
|
||||
|
||||
void Util::sleep(long seconds) {
|
||||
void sleep(long seconds) {
|
||||
#ifdef HAVE_SLEEP
|
||||
::sleep(seconds);
|
||||
#elif defined(HAVE_USLEEP)
|
||||
|
@ -590,7 +613,7 @@ void Util::sleep(long seconds) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void Util::usleep(long microseconds) {
|
||||
void usleep(long microseconds) {
|
||||
#ifdef HAVE_USLEEP
|
||||
::usleep(microseconds);
|
||||
#elif defined(HAVE_WINSOCK2_H)
|
||||
|
@ -625,7 +648,7 @@ void Util::usleep(long microseconds) {
|
|||
#endif
|
||||
}
|
||||
|
||||
bool Util::isNumber(const std::string& what)
|
||||
bool isNumber(const std::string& what)
|
||||
{
|
||||
if(what.empty()) {
|
||||
return false;
|
||||
|
@ -638,7 +661,7 @@ bool Util::isNumber(const std::string& what)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Util::isLowercase(const std::string& what)
|
||||
bool isLowercase(const std::string& what)
|
||||
{
|
||||
if(what.empty()) {
|
||||
return false;
|
||||
|
@ -651,7 +674,7 @@ bool Util::isLowercase(const std::string& what)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Util::isUppercase(const std::string& what)
|
||||
bool isUppercase(const std::string& what)
|
||||
{
|
||||
if(what.empty()) {
|
||||
return false;
|
||||
|
@ -664,7 +687,7 @@ bool Util::isUppercase(const std::string& what)
|
|||
return true;
|
||||
}
|
||||
|
||||
unsigned int Util::alphaToNum(const std::string& alphabets)
|
||||
unsigned int alphaToNum(const std::string& alphabets)
|
||||
{
|
||||
if(alphabets.empty()) {
|
||||
return 0;
|
||||
|
@ -686,7 +709,7 @@ unsigned int Util::alphaToNum(const std::string& alphabets)
|
|||
return num;
|
||||
}
|
||||
|
||||
void Util::mkdirs(const std::string& dirpath)
|
||||
void mkdirs(const std::string& dirpath)
|
||||
{
|
||||
File dir(dirpath);
|
||||
if(dir.isDir()) {
|
||||
|
@ -702,7 +725,7 @@ void Util::mkdirs(const std::string& dirpath)
|
|||
}
|
||||
}
|
||||
|
||||
void Util::convertBitfield(BitfieldMan* dest, const BitfieldMan* src)
|
||||
void convertBitfield(BitfieldMan* dest, const BitfieldMan* src)
|
||||
{
|
||||
size_t numBlock = dest->countBlock();
|
||||
for(size_t index = 0; index < numBlock; ++index) {
|
||||
|
@ -713,7 +736,7 @@ void Util::convertBitfield(BitfieldMan* dest, const BitfieldMan* src)
|
|||
}
|
||||
}
|
||||
|
||||
std::string Util::toString(const BinaryStreamHandle& binaryStream)
|
||||
std::string toString(const BinaryStreamHandle& binaryStream)
|
||||
{
|
||||
std::stringstream strm;
|
||||
char data[2048];
|
||||
|
@ -731,7 +754,7 @@ std::string Util::toString(const BinaryStreamHandle& binaryStream)
|
|||
/**
|
||||
* In linux 2.6, alignment and size should be a multiple of 512.
|
||||
*/
|
||||
void* Util::allocateAlignedMemory(size_t alignment, size_t size)
|
||||
void* allocateAlignedMemory(size_t alignment, size_t size)
|
||||
{
|
||||
void* buffer;
|
||||
int res;
|
||||
|
@ -744,7 +767,7 @@ void* Util::allocateAlignedMemory(size_t alignment, size_t size)
|
|||
#endif // HAVE_POSIX_MEMALIGN
|
||||
|
||||
std::pair<std::string, uint16_t>
|
||||
Util::getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len)
|
||||
getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len)
|
||||
{
|
||||
char host[NI_MAXHOST];
|
||||
char service[NI_MAXSERV];
|
||||
|
@ -757,7 +780,7 @@ Util::getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len)
|
|||
return std::pair<std::string, uint16_t>(host, atoi(service)); // TODO
|
||||
}
|
||||
|
||||
std::string Util::htmlEscape(const std::string& src)
|
||||
std::string htmlEscape(const std::string& src)
|
||||
{
|
||||
std::string dest;
|
||||
for(std::string::const_iterator i = src.begin(); i != src.end(); ++i) {
|
||||
|
@ -780,9 +803,9 @@ std::string Util::htmlEscape(const std::string& src)
|
|||
}
|
||||
|
||||
std::map<size_t, std::string>::value_type
|
||||
Util::parseIndexPath(const std::string& line)
|
||||
parseIndexPath(const std::string& line)
|
||||
{
|
||||
std::pair<std::string, std::string> p = Util::split(line, "=");
|
||||
std::pair<std::string, std::string> p = split(line, "=");
|
||||
size_t index = parseUInt(p.first);
|
||||
if(p.second.empty()) {
|
||||
throw DL_ABORT_EX(StringFormat("Path with index=%u is empty.",
|
||||
|
@ -791,7 +814,7 @@ Util::parseIndexPath(const std::string& line)
|
|||
return std::map<size_t, std::string>::value_type(index, p.second);
|
||||
}
|
||||
|
||||
std::map<size_t, std::string> Util::createIndexPathMap(std::istream& i)
|
||||
std::map<size_t, std::string> createIndexPathMap(std::istream& i)
|
||||
{
|
||||
std::map<size_t, std::string> indexPathMap;
|
||||
std::string line;
|
||||
|
@ -801,8 +824,6 @@ std::map<size_t, std::string> Util::createIndexPathMap(std::istream& i)
|
|||
return indexPathMap;
|
||||
}
|
||||
|
||||
namespace util {
|
||||
|
||||
void generateRandomData(unsigned char* data, size_t length)
|
||||
{
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
|
|
318
src/Util.h
318
src/Util.h
|
@ -82,228 +82,214 @@ inline uint64_t ntoh64(uint64_t x) { return byteswap64(x); }
|
|||
inline uint64_t hton64(uint64_t x) { return byteswap64(x); }
|
||||
#endif // !WORDS_BIGENDIAN
|
||||
|
||||
class Util {
|
||||
public:
|
||||
static void split(std::pair<std::string, std::string>& hp,
|
||||
const std::string& src, char delim);
|
||||
namespace util {
|
||||
|
||||
static std::pair<std::string, std::string>
|
||||
split(const std::string& src, const std::string& delims);
|
||||
void split(std::pair<std::string, std::string>& hp,
|
||||
const std::string& src, char delim);
|
||||
|
||||
template<typename T>
|
||||
static std::string uitos(T value, bool comma = false)
|
||||
{
|
||||
std::string str;
|
||||
if(value == 0) {
|
||||
str = "0";
|
||||
return str;
|
||||
}
|
||||
unsigned int count = 0;
|
||||
while(value) {
|
||||
++count;
|
||||
char digit = value%10+'0';
|
||||
str.insert(str.begin(), digit);
|
||||
value /= 10;
|
||||
if(comma && count > 3 && count%3 == 1) {
|
||||
str.insert(str.begin()+1, ',');
|
||||
}
|
||||
}
|
||||
std::pair<std::string, std::string>
|
||||
split(const std::string& src, const std::string& delims);
|
||||
|
||||
template<typename T>
|
||||
std::string uitos(T value, bool comma = false)
|
||||
{
|
||||
std::string str;
|
||||
if(value == 0) {
|
||||
str = "0";
|
||||
return str;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static std::string itos(T value, bool comma = false)
|
||||
{
|
||||
bool flag = false;
|
||||
if(value < 0) {
|
||||
flag = true;
|
||||
value = -value;
|
||||
unsigned int count = 0;
|
||||
while(value) {
|
||||
++count;
|
||||
char digit = value%10+'0';
|
||||
str.insert(str.begin(), digit);
|
||||
value /= 10;
|
||||
if(comma && count > 3 && count%3 == 1) {
|
||||
str.insert(str.begin()+1, ',');
|
||||
}
|
||||
std::string str = uitos(value, comma);
|
||||
if(flag) {
|
||||
str.insert(str.begin(), '-');
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes difference in micro-seconds between tv1 and tv2,
|
||||
* assuming tv1 is newer than tv2.
|
||||
* If tv1 is older than tv2, then this method returns 0.
|
||||
*/
|
||||
static int64_t difftv(struct timeval tv1, struct timeval tv2);
|
||||
static int32_t difftvsec(struct timeval tv1, struct timeval tv2);
|
||||
|
||||
static const std::string DEFAULT_TRIM_CHARSET;
|
||||
|
||||
static std::string trim(const std::string& src,
|
||||
const std::string& trimCharset = DEFAULT_TRIM_CHARSET);
|
||||
|
||||
static void trimSelf(std::string& str,
|
||||
const std::string& trimCharset = DEFAULT_TRIM_CHARSET);
|
||||
|
||||
static bool startsWith(const std::string& target, const std::string& part);
|
||||
|
||||
static bool endsWith(const std::string& target, const std::string& part);
|
||||
|
||||
static std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr);
|
||||
|
||||
static std::string urlencode(const unsigned char* target, size_t len);
|
||||
|
||||
static std::string urlencode(const std::string& target)
|
||||
{
|
||||
return urlencode((const unsigned char*)target.c_str(), target.size());
|
||||
template<typename T>
|
||||
std::string itos(T value, bool comma = false)
|
||||
{
|
||||
bool flag = false;
|
||||
if(value < 0) {
|
||||
flag = true;
|
||||
value = -value;
|
||||
}
|
||||
|
||||
static bool inRFC3986ReservedChars(const char c);
|
||||
|
||||
static bool inRFC3986UnreservedChars(const char c);
|
||||
|
||||
static std::string urldecode(const std::string& target);
|
||||
|
||||
static std::string torrentUrlencode(const unsigned char* target, size_t len);
|
||||
|
||||
static std::string torrentUrlencode(const std::string& target)
|
||||
{
|
||||
return torrentUrlencode(reinterpret_cast<const unsigned char*>(target.c_str()),
|
||||
target.size());
|
||||
std::string str = uitos(value, comma);
|
||||
if(flag) {
|
||||
str.insert(str.begin(), '-');
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
static std::string toHex(const unsigned char* src, size_t len);
|
||||
/**
|
||||
* Computes difference in micro-seconds between tv1 and tv2,
|
||||
* assuming tv1 is newer than tv2.
|
||||
* If tv1 is older than tv2, then this method returns 0.
|
||||
*/
|
||||
int64_t difftv(struct timeval tv1, struct timeval tv2);
|
||||
int32_t difftvsec(struct timeval tv1, struct timeval tv2);
|
||||
|
||||
static std::string toHex(const char* src, size_t len)
|
||||
{
|
||||
return toHex(reinterpret_cast<const unsigned char*>(src), len);
|
||||
}
|
||||
extern const std::string DEFAULT_TRIM_CHARSET;
|
||||
|
||||
static std::string toHex(const std::string& src)
|
||||
{
|
||||
return toHex(reinterpret_cast<const unsigned char*>(src.c_str()), src.size());
|
||||
}
|
||||
std::string trim(const std::string& src,
|
||||
const std::string& trimCharset = DEFAULT_TRIM_CHARSET);
|
||||
|
||||
static FILE* openFile(const std::string& filename, const std::string& mode);
|
||||
void trimSelf(std::string& str,
|
||||
const std::string& trimCharset = DEFAULT_TRIM_CHARSET);
|
||||
|
||||
static bool isPowerOf(int num, int base);
|
||||
bool startsWith(const std::string& target, const std::string& part);
|
||||
|
||||
static std::string secfmt(time_t sec);
|
||||
bool endsWith(const std::string& target, const std::string& part);
|
||||
|
||||
static int32_t parseInt(const std::string& s, int32_t base = 10);
|
||||
std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr);
|
||||
|
||||
static uint32_t parseUInt(const std::string& s, int base = 10);
|
||||
std::string urlencode(const unsigned char* target, size_t len);
|
||||
|
||||
static int64_t parseLLInt(const std::string& s, int32_t base = 10);
|
||||
std::string urlencode(const std::string& target);
|
||||
|
||||
static uint64_t parseULLInt(const std::string& s, int base = 10);
|
||||
bool inRFC3986ReservedChars(const char c);
|
||||
|
||||
static IntSequence parseIntRange(const std::string& src);
|
||||
bool inRFC3986UnreservedChars(const char c);
|
||||
|
||||
// this function temporarily put here
|
||||
static std::string getContentDispositionFilename(const std::string& header);
|
||||
std::string urldecode(const std::string& target);
|
||||
|
||||
static std::string randomAlpha(size_t length,
|
||||
const SharedHandle<Randomizer>& randomizer);
|
||||
std::string torrentUrlencode(const unsigned char* target, size_t len);
|
||||
|
||||
static std::string toUpper(const std::string& src);
|
||||
std::string torrentUrlencode(const std::string& target);
|
||||
|
||||
static std::string toLower(const std::string& src);
|
||||
std::string toHex(const unsigned char* src, size_t len);
|
||||
|
||||
static bool isNumbersAndDotsNotation(const std::string& name);
|
||||
std::string toHex(const char* src, size_t len);
|
||||
|
||||
static void setGlobalSignalHandler(int signal, void (*handler)(int), int flags);
|
||||
std::string toHex(const std::string& src);
|
||||
|
||||
static std::string getHomeDir();
|
||||
FILE* openFile(const std::string& filename, const std::string& mode);
|
||||
|
||||
static int64_t getRealSize(const std::string& sizeWithUnit);
|
||||
bool isPowerOf(int num, int base);
|
||||
|
||||
static std::string abbrevSize(int64_t size);
|
||||
std::string secfmt(time_t sec);
|
||||
|
||||
template<typename InputIterator>
|
||||
static void toStream
|
||||
(InputIterator first, InputIterator last, std::ostream& os)
|
||||
{
|
||||
os << _("Files:") << "\n";
|
||||
os << "idx|path/length" << "\n";
|
||||
os << "===+===========================================================================" << "\n";
|
||||
int32_t count = 1;
|
||||
for(; first != last; ++first, ++count) {
|
||||
int32_t parseInt(const std::string& s, int32_t base = 10);
|
||||
|
||||
uint32_t parseUInt(const std::string& s, int base = 10);
|
||||
|
||||
int64_t parseLLInt(const std::string& s, int32_t base = 10);
|
||||
|
||||
uint64_t parseULLInt(const std::string& s, int base = 10);
|
||||
|
||||
IntSequence parseIntRange(const std::string& src);
|
||||
|
||||
// this function temporarily put here
|
||||
std::string getContentDispositionFilename(const std::string& header);
|
||||
|
||||
std::string randomAlpha(size_t length,
|
||||
const SharedHandle<Randomizer>& randomizer);
|
||||
|
||||
std::string toUpper(const std::string& src);
|
||||
|
||||
std::string toLower(const std::string& src);
|
||||
|
||||
bool isNumbersAndDotsNotation(const std::string& name);
|
||||
|
||||
void setGlobalSignalHandler(int signal, void (*handler)(int), int flags);
|
||||
|
||||
std::string getHomeDir();
|
||||
|
||||
int64_t getRealSize(const std::string& sizeWithUnit);
|
||||
|
||||
std::string abbrevSize(int64_t size);
|
||||
|
||||
template<typename InputIterator>
|
||||
void toStream
|
||||
(InputIterator first, InputIterator last, std::ostream& os)
|
||||
{
|
||||
os << _("Files:") << "\n";
|
||||
os << "idx|path/length" << "\n";
|
||||
os << "===+===========================================================================" << "\n";
|
||||
int32_t count = 1;
|
||||
for(; first != last; ++first, ++count) {
|
||||
os << std::setw(3) << count << "|" << (*first)->getPath() << "\n";
|
||||
os << " |" << Util::abbrevSize((*first)->getLength()) << "B ("
|
||||
<< Util::uitos((*first)->getLength(), true) << ")\n";
|
||||
os << " |" << util::abbrevSize((*first)->getLength()) << "B ("
|
||||
<< util::uitos((*first)->getLength(), true) << ")\n";
|
||||
os << "---+---------------------------------------------------------------------------" << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void sleep(long seconds);
|
||||
void sleep(long seconds);
|
||||
|
||||
static void usleep(long microseconds);
|
||||
void usleep(long microseconds);
|
||||
|
||||
static bool isNumber(const std::string& what);
|
||||
bool isNumber(const std::string& what);
|
||||
|
||||
static bool isLowercase(const std::string& what);
|
||||
bool isLowercase(const std::string& what);
|
||||
|
||||
static bool isUppercase(const std::string& what);
|
||||
bool isUppercase(const std::string& what);
|
||||
|
||||
/**
|
||||
* Converts alphabets to unsigned int, assuming alphabets as a base 26
|
||||
* integer and 'a' or 'A' is 0.
|
||||
* This function assumes alphabets includes only a-z.
|
||||
* Upper case are allowed but all letters must be upper case.
|
||||
* If overflow occurs, returns 0.
|
||||
*/
|
||||
static unsigned int alphaToNum(const std::string& alphabets);
|
||||
/**
|
||||
* Converts alphabets to unsigned int, assuming alphabets as a base 26
|
||||
* integer and 'a' or 'A' is 0.
|
||||
* This function assumes alphabets includes only a-z.
|
||||
* Upper case are allowed but all letters must be upper case.
|
||||
* If overflow occurs, returns 0.
|
||||
*/
|
||||
unsigned int alphaToNum(const std::string& alphabets);
|
||||
|
||||
static void mkdirs(const std::string& dirpath);
|
||||
void mkdirs(const std::string& dirpath);
|
||||
|
||||
static void convertBitfield(BitfieldMan* dest, const BitfieldMan* src);
|
||||
void convertBitfield(BitfieldMan* dest, const BitfieldMan* src);
|
||||
|
||||
// binaryStream has to be opened before calling this function.
|
||||
static std::string toString(const SharedHandle<BinaryStream>& binaryStream);
|
||||
// binaryStream has to be opened before calling this function.
|
||||
std::string toString(const SharedHandle<BinaryStream>& binaryStream);
|
||||
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
static void* allocateAlignedMemory(size_t alignment, size_t size);
|
||||
void* allocateAlignedMemory(size_t alignment, size_t size);
|
||||
#endif // HAVE_POSIX_MEMALIGN
|
||||
|
||||
static std::pair<std::string, uint16_t>
|
||||
getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len);
|
||||
std::pair<std::string, uint16_t>
|
||||
getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len);
|
||||
|
||||
static std::string htmlEscape(const std::string& src);
|
||||
std::string htmlEscape(const std::string& src);
|
||||
|
||||
// Joins path element specified in [first, last). If ".." is found,
|
||||
// it eats the previous element if it exists. If "." is found, it
|
||||
// is just ignored and it is not appeared in the result.
|
||||
template<typename InputIterator>
|
||||
static std::string joinPath(InputIterator first, InputIterator last)
|
||||
{
|
||||
std::deque<std::string> elements;
|
||||
for(;first != last; ++first) {
|
||||
if(*first == "..") {
|
||||
if(!elements.empty()) {
|
||||
elements.pop_back();
|
||||
}
|
||||
} else if(*first == ".") {
|
||||
// do nothing
|
||||
} else {
|
||||
elements.push_back(*first);
|
||||
// Joins path element specified in [first, last). If ".." is found,
|
||||
// it eats the previous element if it exists. If "." is found, it
|
||||
// is just ignored and it is not appeared in the result.
|
||||
template<typename InputIterator>
|
||||
std::string joinPath(InputIterator first, InputIterator last)
|
||||
{
|
||||
std::deque<std::string> elements;
|
||||
for(;first != last; ++first) {
|
||||
if(*first == "..") {
|
||||
if(!elements.empty()) {
|
||||
elements.pop_back();
|
||||
}
|
||||
} else if(*first == ".") {
|
||||
// do nothing
|
||||
} else {
|
||||
elements.push_back(*first);
|
||||
}
|
||||
return strjoin(elements.begin(), elements.end(), "/");
|
||||
}
|
||||
return strjoin(elements.begin(), elements.end(), "/");
|
||||
}
|
||||
|
||||
// Parses INDEX=PATH format string. INDEX must be an unsigned
|
||||
// integer.
|
||||
static std::map<size_t, std::string>::value_type
|
||||
parseIndexPath(const std::string& line);
|
||||
// Parses INDEX=PATH format string. INDEX must be an unsigned
|
||||
// integer.
|
||||
std::map<size_t, std::string>::value_type
|
||||
parseIndexPath(const std::string& line);
|
||||
|
||||
static std::map<size_t, std::string> createIndexPathMap(std::istream& i);
|
||||
};
|
||||
std::map<size_t, std::string> createIndexPathMap(std::istream& i);
|
||||
|
||||
/**
|
||||
* Take a string src which is a deliminated list and add its elements
|
||||
* into result. result is stored in out.
|
||||
*/
|
||||
template<typename OutputIterator>
|
||||
static OutputIterator split(const std::string& src, OutputIterator out,
|
||||
const std::string& delims, bool doTrim = false)
|
||||
OutputIterator split(const std::string& src, OutputIterator out,
|
||||
const std::string& delims, bool doTrim = false)
|
||||
{
|
||||
std::string::size_type p = 0;
|
||||
while(1) {
|
||||
|
@ -311,7 +297,7 @@ static OutputIterator split(const std::string& src, OutputIterator out,
|
|||
if(np == std::string::npos) {
|
||||
std::string term = src.substr(p);
|
||||
if(doTrim) {
|
||||
term = Util::trim(term);
|
||||
term = util::trim(term);
|
||||
}
|
||||
if(!term.empty()) {
|
||||
*out = term;
|
||||
|
@ -321,7 +307,7 @@ static OutputIterator split(const std::string& src, OutputIterator out,
|
|||
}
|
||||
std::string term = src.substr(p, np-p);
|
||||
if(doTrim) {
|
||||
term = Util::trim(term);
|
||||
term = util::trim(term);
|
||||
}
|
||||
p = np+1;
|
||||
if(!term.empty()) {
|
||||
|
@ -332,8 +318,6 @@ static OutputIterator split(const std::string& src, OutputIterator out,
|
|||
return out;
|
||||
}
|
||||
|
||||
namespace util {
|
||||
|
||||
void generateRandomData(unsigned char* data, size_t length);
|
||||
|
||||
} // namespace util
|
||||
|
|
|
@ -63,7 +63,7 @@ static void mlStartElement(void* userData, const xmlChar* name, const xmlChar**
|
|||
if(*p == 0) {
|
||||
break;
|
||||
}
|
||||
std::string value = Util::trim((const char*)*p++);
|
||||
std::string value = util::trim((const char*)*p++);
|
||||
attrmap[name] = value;
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ static void mlEndElement(void* userData, const xmlChar* name)
|
|||
SessionData* sd = reinterpret_cast<SessionData*>(userData);
|
||||
std::string characters;
|
||||
if(sd->_stm->needsCharactersBuffering()) {
|
||||
characters = Util::trim(sd->_charactersStack.front());
|
||||
characters = util::trim(sd->_charactersStack.front());
|
||||
sd->_charactersStack.pop_front();
|
||||
}
|
||||
sd->_stm->endElement((const char*)name, characters);
|
||||
|
|
|
@ -67,7 +67,7 @@ static void mlStartElement(void* userData, const xmlChar* name,
|
|||
if(*p == 0) {
|
||||
break;
|
||||
}
|
||||
std::string value = Util::trim((const char*)*p++);
|
||||
std::string value = util::trim((const char*)*p++);
|
||||
attrmap[name] = value;
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ static void mlEndElement(void* userData, const xmlChar* name)
|
|||
SessionData* sd = reinterpret_cast<SessionData*>(userData);
|
||||
std::string characters;
|
||||
if(sd->_stm->needsCharactersBuffering()) {
|
||||
characters = Util::trim(sd->_charactersStack.top());
|
||||
characters = util::trim(sd->_charactersStack.top());
|
||||
sd->_charactersStack.pop();
|
||||
}
|
||||
sd->_stm->endElement((const char*)name, characters);
|
||||
|
|
|
@ -82,7 +82,7 @@ static const BDE BDE_COMPLETE = BDE("complete");
|
|||
|
||||
static BDE createGIDResponse(int32_t gid)
|
||||
{
|
||||
return BDE(Util::itos(gid));
|
||||
return BDE(util::itos(gid));
|
||||
}
|
||||
|
||||
static BDE addRequestGroup(const SharedHandle<RequestGroup>& group,
|
||||
|
@ -221,7 +221,7 @@ BDE AddMetalinkXmlRpcMethod::process
|
|||
BDE gids = BDE::list();
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
||||
result.begin(); i != result.end(); ++i) {
|
||||
gids << BDE(Util::itos((*i)->getGID()));
|
||||
gids << BDE(util::itos((*i)->getGID()));
|
||||
}
|
||||
return gids;
|
||||
} else {
|
||||
|
@ -239,7 +239,7 @@ BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
|||
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
||||
}
|
||||
|
||||
int32_t gid = Util::parseInt(params[0].s());
|
||||
int32_t gid = util::parseInt(params[0].s());
|
||||
|
||||
SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid);
|
||||
|
||||
|
@ -265,27 +265,27 @@ BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
|||
static void gatherProgressCommon
|
||||
(BDE& entryDict, const SharedHandle<RequestGroup>& group)
|
||||
{
|
||||
entryDict["gid"] = Util::itos(group->getGID());
|
||||
entryDict["gid"] = util::itos(group->getGID());
|
||||
// This is "filtered" total length if --select-file is used.
|
||||
entryDict["totalLength"] = Util::uitos(group->getTotalLength());
|
||||
entryDict["totalLength"] = util::uitos(group->getTotalLength());
|
||||
// This is "filtered" total length if --select-file is used.
|
||||
entryDict["completedLength"] = Util::uitos(group->getCompletedLength());
|
||||
entryDict["completedLength"] = util::uitos(group->getCompletedLength());
|
||||
TransferStat stat = group->calculateStat();
|
||||
entryDict["downloadSpeed"] = Util::uitos(stat.getDownloadSpeed());
|
||||
entryDict["uploadSpeed"] = Util::uitos(stat.getUploadSpeed());
|
||||
entryDict["uploadLength"] = Util::uitos(stat.getAllTimeUploadLength());
|
||||
entryDict["connections"] = Util::uitos(group->getNumConnection());
|
||||
entryDict["downloadSpeed"] = util::uitos(stat.getDownloadSpeed());
|
||||
entryDict["uploadSpeed"] = util::uitos(stat.getUploadSpeed());
|
||||
entryDict["uploadLength"] = util::uitos(stat.getAllTimeUploadLength());
|
||||
entryDict["connections"] = util::uitos(group->getNumConnection());
|
||||
SharedHandle<PieceStorage> ps = group->getPieceStorage();
|
||||
if(!ps.isNull()) {
|
||||
if(ps->getBitfieldLength() > 0) {
|
||||
entryDict["bitfield"] = Util::toHex(ps->getBitfield(),
|
||||
entryDict["bitfield"] = util::toHex(ps->getBitfield(),
|
||||
ps->getBitfieldLength());
|
||||
}
|
||||
}
|
||||
entryDict["pieceLength"] =
|
||||
Util::uitos(group->getDownloadContext()->getPieceLength());
|
||||
util::uitos(group->getDownloadContext()->getPieceLength());
|
||||
entryDict["numPieces"] =
|
||||
Util::uitos(group->getDownloadContext()->getNumPieces());
|
||||
util::uitos(group->getDownloadContext()->getNumPieces());
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
|
@ -293,7 +293,7 @@ static void gatherProgressBitTorrent
|
|||
(BDE& entryDict, const BDE& torrentAttrs, const SharedHandle<BtRegistry>& btreg)
|
||||
{
|
||||
const std::string& infoHash = torrentAttrs[bittorrent::INFO_HASH].s();
|
||||
entryDict["infoHash"] = Util::toHex(infoHash);
|
||||
entryDict["infoHash"] = util::toHex(infoHash);
|
||||
|
||||
SharedHandle<PeerStorage> peerStorage = btreg->get(infoHash)._peerStorage;
|
||||
assert(!peerStorage.isNull());
|
||||
|
@ -310,17 +310,17 @@ static void gatherPeer(BDE& peers, const SharedHandle<PeerStorage>& ps)
|
|||
for(std::deque<SharedHandle<Peer> >::const_iterator i =
|
||||
activePeers.begin(); i != activePeers.end(); ++i) {
|
||||
BDE peerEntry = BDE::dict();
|
||||
peerEntry["peerId"] = Util::torrentUrlencode((*i)->getPeerId(),
|
||||
peerEntry["peerId"] = util::torrentUrlencode((*i)->getPeerId(),
|
||||
PEER_ID_LENGTH);
|
||||
peerEntry["ip"] = (*i)->ipaddr;
|
||||
peerEntry["port"] = Util::uitos((*i)->port);
|
||||
peerEntry["bitfield"] = Util::toHex((*i)->getBitfield(),
|
||||
peerEntry["port"] = util::uitos((*i)->port);
|
||||
peerEntry["bitfield"] = util::toHex((*i)->getBitfield(),
|
||||
(*i)->getBitfieldLength());
|
||||
peerEntry["amChoking"] = (*i)->amChoking()?BDE_TRUE:BDE_FALSE;
|
||||
peerEntry["peerChoking"] = (*i)->peerChoking()?BDE_TRUE:BDE_FALSE;
|
||||
TransferStat stat = ps->getTransferStatFor(*i);
|
||||
peerEntry["downloadSpeed"] = Util::uitos(stat.getDownloadSpeed());
|
||||
peerEntry["uploadSpeed"] = Util::uitos(stat.getUploadSpeed());
|
||||
peerEntry["downloadSpeed"] = util::uitos(stat.getDownloadSpeed());
|
||||
peerEntry["uploadSpeed"] = util::uitos(stat.getUploadSpeed());
|
||||
peerEntry["seeder"] = (*i)->isSeeder()?BDE_TRUE:BDE_FALSE;
|
||||
peers << peerEntry;
|
||||
}
|
||||
|
@ -344,8 +344,8 @@ static void gatherProgress
|
|||
static void gatherStoppedDownload
|
||||
(BDE& entryDict, const SharedHandle<DownloadResult>& ds)
|
||||
{
|
||||
entryDict["gid"] = Util::itos(ds->gid);
|
||||
entryDict["errorCode"] = Util::itos(static_cast<int>(ds->result));
|
||||
entryDict["gid"] = util::itos(ds->gid);
|
||||
entryDict["errorCode"] = util::itos(static_cast<int>(ds->result));
|
||||
if(ds->result == downloadresultcode::IN_PROGRESS) {
|
||||
entryDict["status"] = BDE_REMOVED;
|
||||
} else if(ds->result == downloadresultcode::FINISHED) {
|
||||
|
@ -372,10 +372,10 @@ static void createFileEntry(BDE& files, InputIterator first, InputIterator last)
|
|||
size_t index = 1;
|
||||
for(; first != last; ++first, ++index) {
|
||||
BDE entry = BDE::dict();
|
||||
entry["index"] = Util::uitos(index);
|
||||
entry["index"] = util::uitos(index);
|
||||
entry["path"] = (*first)->getPath();
|
||||
entry["selected"] = (*first)->isRequested()?BDE_TRUE:BDE_FALSE;
|
||||
entry["length"] = Util::uitos((*first)->getLength());
|
||||
entry["length"] = util::uitos((*first)->getLength());
|
||||
files << entry;
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ BDE GetFilesXmlRpcMethod::process
|
|||
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
||||
}
|
||||
|
||||
int32_t gid = Util::parseInt(params[0].s());
|
||||
int32_t gid = util::parseInt(params[0].s());
|
||||
|
||||
BDE files = BDE::list();
|
||||
SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
|
||||
|
@ -421,7 +421,7 @@ BDE GetUrisXmlRpcMethod::process
|
|||
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
||||
}
|
||||
|
||||
int32_t gid = Util::parseInt(params[0].s());
|
||||
int32_t gid = util::parseInt(params[0].s());
|
||||
|
||||
SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
|
||||
if(group.isNull()) {
|
||||
|
@ -454,7 +454,7 @@ BDE GetPeersXmlRpcMethod::process
|
|||
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
||||
}
|
||||
|
||||
int32_t gid = Util::parseInt(params[0].s());
|
||||
int32_t gid = util::parseInt(params[0].s());
|
||||
|
||||
SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
|
||||
if(group.isNull()) {
|
||||
|
@ -486,7 +486,7 @@ BDE TellStatusXmlRpcMethod::process
|
|||
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
||||
}
|
||||
|
||||
int32_t gid = Util::parseInt(params[0].s());
|
||||
int32_t gid = util::parseInt(params[0].s());
|
||||
|
||||
SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid);
|
||||
|
||||
|
@ -585,7 +585,7 @@ BDE ChangeOptionXmlRpcMethod::process
|
|||
if(params.empty() || !params[0].isString()) {
|
||||
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
||||
}
|
||||
int32_t gid = Util::parseInt(params[0].s());
|
||||
int32_t gid = util::parseInt(params[0].s());
|
||||
|
||||
SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
|
||||
if(group.isNull()) {
|
||||
|
|
|
@ -185,7 +185,7 @@ void IntXmlRpcRequestParserState::endElement
|
|||
const std::string& characters)
|
||||
{
|
||||
try {
|
||||
int64_t value = Util::parseLLInt(characters);
|
||||
int64_t value = util::parseLLInt(characters);
|
||||
stm->setCurrentFrameValue(BDE(value));
|
||||
} catch(RecoverableException& e) {
|
||||
// nothing to do here: We just leave current frame value to BDE::none
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue