summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-11-12 19:24:38 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-11-12 19:24:38 +0900
commit0da2468d6b4ed4ef9f96cd3d50aa6e02da863da0 (patch)
tree4790558d314e6ceb774a095e8144f20480017084 /src
parent2e5d9b056f2cf398d8996d93a4c7fbc1fbe66221 (diff)
Removed strappend
Diffstat (limited to 'src')
-rw-r--r--src/HandshakeExtensionMessage.cc17
-rw-r--r--src/HttpConnection.cc3
-rw-r--r--src/HttpRequest.cc41
-rw-r--r--src/HttpServer.cc33
-rw-r--r--src/LpdMessageDispatcher.cc16
-rw-r--r--src/OptionHandlerImpl.cc30
-rw-r--r--src/Peer.cc3
-rw-r--r--src/ServerStat.cc22
-rw-r--r--src/a2functional.h57
-rw-r--r--src/util.cc12
10 files changed, 103 insertions, 131 deletions
diff --git a/src/HandshakeExtensionMessage.cc b/src/HandshakeExtensionMessage.cc
index 3fae69d8..6c494c98 100644
--- a/src/HandshakeExtensionMessage.cc
+++ b/src/HandshakeExtensionMessage.cc
@@ -82,20 +82,15 @@ std::string HandshakeExtensionMessage::getPayload()
std::string HandshakeExtensionMessage::toString() const
{
- std::string s = getExtensionName();
- if(!clientVersion_.empty()) {
- strappend(s, " client=", util::percentEncode(clientVersion_));
- }
- if(tcpPort_ > 0) {
- strappend(s, ", tcpPort=", util::uitos(tcpPort_));
- }
- if(metadataSize_) {
- strappend(s, ", metadataSize=", util::uitos(metadataSize_));
- }
+ std::string s(fmt("%s client=%s, tcpPort=%u, metadataSize=%lu",
+ getExtensionName().c_str(),
+ util::percentEncode(clientVersion_).c_str(),
+ tcpPort_,
+ metadataSize_));
for(std::map<std::string, uint8_t>::const_iterator itr = extensions_.begin(),
eoi = extensions_.end(); itr != eoi; ++itr) {
const std::map<std::string, uint8_t>::value_type& vt = *itr;
- strappend(s, ", ", vt.first, "=", util::uitos(vt.second));
+ s += fmt(", %s=%u", vt.first.c_str(), vt.second);
}
return s;
}
diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc
index 8b511445..b7c1bb70 100644
--- a/src/HttpConnection.cc
+++ b/src/HttpConnection.cc
@@ -97,7 +97,8 @@ std::string HttpConnection::eraseConfidentialInfo(const std::string& request)
vend(A2_PROXY_AUTH_HEADER)-1)) {
result += "Proxy-Authorization: Basic ********\n";
} else {
- strappend(result, line, "\n");
+ result += line;
+ result += "\n";
}
}
return result;
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index 8d3c5937..4660d18c 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -131,7 +131,7 @@ std::string getHostText(const std::string& host, uint16_t port)
{
std::string hosttext = host;
if(!(port == 80 || port == 443)) {
- strappend(hosttext, ":", util::uitos(port));
+ hosttext += fmt(":%u", port);;
}
return hosttext;
}
@@ -171,7 +171,8 @@ std::string HttpRequest::createRequest()
std::string acceptTypes = "*/*";
for(std::vector<std::string>::const_iterator i = acceptTypes_.begin(),
eoi = acceptTypes_.end(); i != eoi; ++i) {
- strappend(acceptTypes, ",", (*i));
+ acceptTypes += ",";
+ acceptTypes += *i;
}
builtinHds.push_back(std::make_pair("Accept:", acceptTypes));
if(contentEncodingEnabled_) {
@@ -242,7 +243,8 @@ std::string HttpRequest::createRequest()
getProtocol() == Request::PROTO_HTTPS);
for(std::vector<Cookie>::const_iterator itr = cookies.begin(),
eoi = cookies.end(); itr != eoi; ++itr) {
- strappend(cookiesValue, (*itr).toString(), ";");
+ cookiesValue += (*itr).toString();
+ cookiesValue += ";";
}
if(!cookiesValue.empty()) {
builtinHds.push_back(std::make_pair("Cookie:", cookiesValue));
@@ -263,28 +265,34 @@ std::string HttpRequest::createRequest()
}
}
if(j == jend) {
- strappend(requestLine, (*i).first, " ", (*i).second, A2STR::CRLF);
+ requestLine += (*i).first;
+ requestLine += " ";
+ requestLine += (*i).second;
+ requestLine += "\r\n";
}
}
// append additional headers given by user.
for(std::vector<std::string>::const_iterator i = headers_.begin(),
eoi = headers_.end(); i != eoi; ++i) {
- strappend(requestLine, (*i), A2STR::CRLF);
+ requestLine += *i;
+ requestLine += "\r\n";
}
- requestLine += A2STR::CRLF;
+ requestLine += "\r\n";
return requestLine;
}
std::string HttpRequest::createProxyRequest() const
{
assert(proxyRequest_);
- std::string hostport = getURIHost();
- strappend(hostport, ":", util::uitos(getPort()));
-
- std::string requestLine = "CONNECT ";
- strappend(requestLine, hostport, " HTTP/1.1\r\n");
- strappend(requestLine, "User-Agent: ", userAgent_, "\r\n");
- strappend(requestLine, "Host: ", hostport, "\r\n");
+ //std::string hostport(fmt("%s:%u", getURIHost().c_str(), getPort()));
+ std::string requestLine(fmt("CONNECT %s:%u HTTP/1.1\r\n"
+ "User-Agent: %s\r\n"
+ "Host: %s:%u\r\n",
+ getURIHost().c_str(),
+ getPort(),
+ userAgent_.c_str(),
+ getURIHost().c_str(),
+ getPort()));
// TODO Is "Proxy-Connection" needed here?
// if(request->isKeepAliveEnabled() || request->isPipeliningEnabled()) {
// requestLine += "Proxy-Connection: Keep-Alive\r\n";
@@ -293,9 +301,12 @@ std::string HttpRequest::createProxyRequest() const
// }
if(!proxyRequest_->getUsername().empty()) {
std::pair<std::string, std::string> auth = getProxyAuthString();
- strappend(requestLine, auth.first, " ", auth.second, A2STR::CRLF);
+ requestLine += auth.first;
+ requestLine += " ";
+ requestLine += auth.second;
+ requestLine += "\r\n";
}
- requestLine += A2STR::CRLF;
+ requestLine += "\r\n";
return requestLine;
}
diff --git a/src/HttpServer.cc b/src/HttpServer.cc
index 3247457c..a30cc9ae 100644
--- a/src/HttpServer.cc
+++ b/src/HttpServer.cc
@@ -173,21 +173,26 @@ void HttpServer::feedResponse(const std::string& status,
const std::string& contentType)
{
std::string httpDate = Time().toHTTPDate();
- std::string header = "HTTP/1.1 ";
- strappend(header, status, "\r\n",
- "Date: ", httpDate, "\r\n",
- "Content-Type: ", contentType, "\r\n");
- strappend(header, "Content-Length: ", util::uitos(text.size()), "\r\n",
- "Expires: ", httpDate, "\r\n",
- "Cache-Control: no-cache\r\n");
+ std::string header= fmt("HTTP/1.1 %s\r\n"
+ "Date: %s\r\n"
+ "Content-Type: %s\r\n"
+ "Content-Length: %lu\r\n"
+ "Expires: %s\r\n"
+ "Cache-Control: no-cache\r\n"
+ "%s%s",
+ status.c_str(),
+ httpDate.c_str(),
+ contentType.c_str(),
+ static_cast<unsigned long>(text.size()),
+ httpDate.c_str(),
+ supportsGZip() ?
+ "Content-Encoding: gzip\r\n" : "",
+ !supportsPersistentConnection() ?
+ "Connection: close\r\n" : "");
if(!allowOrigin_.empty()) {
- strappend(header, "Access-Control-Allow-Origin: ", allowOrigin_, "\r\n");
- }
- if(supportsGZip()) {
- header += "Content-Encoding: gzip\r\n";
- }
- if(!supportsPersistentConnection()) {
- header += "Connection: close\r\n";
+ header += "Access-Control-Allow-Origin: ";
+ header += allowOrigin_;
+ header += "\r\n";
}
if(!headers.empty()) {
header += headers;
diff --git a/src/LpdMessageDispatcher.cc b/src/LpdMessageDispatcher.cc
index fcbfd2b3..9ab36e2a 100644
--- a/src/LpdMessageDispatcher.cc
+++ b/src/LpdMessageDispatcher.cc
@@ -107,13 +107,15 @@ std::string createLpdRequest
(const std::string& multicastAddress, uint16_t multicastPort,
const std::string& infoHash, uint16_t port)
{
- std::string req = "BT-SEARCH * HTTP/1.1\r\n";
- strappend(req, "Host: ", multicastAddress, A2STR::COLON_C,
- util::uitos(multicastPort), A2STR::CRLF);
- strappend(req, "Port: ", util::uitos(port), A2STR::CRLF);
- strappend(req, "Infohash: ", util::toHex(infoHash), A2STR::CRLF);
- req += "\r\n\r\n";
- return req;
+ return fmt("BT-SEARCH * HTTP/1.1\r\n"
+ "Host: %s:%u\r\n"
+ "Port: %u\r\n"
+ "Infohash: %s\r\n"
+ "\r\n\r\n",
+ multicastAddress.c_str(),
+ multicastPort,
+ port,
+ util::toHex(infoHash).c_str());
}
} // namespace bittorrent
diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc
index e34b7ace..1f0d500c 100644
--- a/src/OptionHandlerImpl.cc
+++ b/src/OptionHandlerImpl.cc
@@ -89,7 +89,8 @@ void BooleanOptionHandler::parseArg(Option& option, const std::string& optarg)
option.put(pref_, A2_V_FALSE);
} else {
std::string msg = pref_->k;
- strappend(msg, " ", _("must be either 'true' or 'false'."));
+ msg += " ";
+ msg += _("must be either 'true' or 'false'.");
throw DL_ABORT_EX(msg);
}
}
@@ -123,10 +124,10 @@ void IntegerRangeOptionHandler::parseArg
int v = sgl.next();
if(v < min_ || max_ < v) {
std::string msg = pref_->k;
- strappend(msg, " ", _("must be between %s and %s."));
+ msg += " ";
+ msg += _("must be between %s and %s.");
throw DL_ABORT_EX
- (fmt(msg.c_str(), util::itos(min_).c_str(),
- util::itos(max_).c_str()));
+ (fmt(msg.c_str(), util::itos(min_).c_str(), util::itos(max_).c_str()));
}
option.put(pref_, optarg);
}
@@ -320,7 +321,8 @@ void CumulativeOptionHandler::parseArg
(Option& option, const std::string& optarg)
{
std::string value = option.get(pref_);
- strappend(value, optarg, delim_);
+ value += optarg;
+ value += delim_;
option.put(pref_, value);
}
@@ -344,7 +346,8 @@ void IndexOutOptionHandler::parseArg(Option& option, const std::string& optarg)
// See optarg is in the fomrat of "INDEX=PATH"
util::parseIndexPath(optarg);
std::string value = option.get(pref_);
- strappend(value, optarg, "\n");
+ value += optarg;
+ value += "\n";
option.put(pref_, value);
}
@@ -445,14 +448,17 @@ void ParameterOptionHandler::parseArg(Option& option, const std::string& optarg)
std::find(validParamValues_.begin(), validParamValues_.end(), optarg);
if(itr == validParamValues_.end()) {
std::string msg = pref_->k;
- strappend(msg, " ", _("must be one of the following:"));
+ msg += " ";
+ msg += _("must be one of the following:");
if(validParamValues_.size() == 0) {
msg += "''";
} else {
for(std::vector<std::string>::const_iterator itr =
validParamValues_.begin(), eoi = validParamValues_.end();
itr != eoi; ++itr) {
- strappend(msg, "'", *itr, "' ");
+ msg += "'";
+ msg += *itr;
+ msg += "' ";
}
}
throw DL_ABORT_EX(msg);
@@ -540,7 +546,9 @@ void HttpProxyUserOptionHandler::parseArg
if(uri.size() > 7) {
uri += "@";
}
- strappend(uri, req.getHost(),A2STR::COLON_C,util::uitos(req.getPort()));
+ uri += req.getHost();
+ uri += ":";
+ uri += util::uitos(req.getPort());
option.put(proxyPref, uri);
}
}
@@ -584,7 +592,9 @@ void HttpProxyPasswdOptionHandler::parseArg
if(uri.size() > 7) {
uri += "@";
}
- strappend(uri, req.getHost(), A2STR::COLON_C,util::itos(req.getPort()));
+ uri += req.getHost();
+ uri += ":";
+ uri += util::itos(req.getPort());
option.put(proxyPref, uri);
}
}
diff --git a/src/Peer.cc b/src/Peer.cc
index 0423bfeb..fc690cc9 100644
--- a/src/Peer.cc
+++ b/src/Peer.cc
@@ -50,6 +50,7 @@ namespace aria2 {
Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
ipaddr_(ipaddr),
port_(port),
+ id_(fmt("%s(%u)", ipaddr_.c_str(), port_)),
firstContactTime_(global::wallclock()),
badConditionStartTime_(0),
seeder_(false),
@@ -60,8 +61,6 @@ Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
{
memset(peerId_, 0, PEER_ID_LENGTH);
resetStatus();
- id_ = ipaddr_;
- strappend(id_, A2STR::COLON_C, util::uitos(port_));
}
Peer::~Peer()
diff --git a/src/ServerStat.cc b/src/ServerStat.cc
index 16b8cad4..0f7b7aed 100644
--- a/src/ServerStat.cc
+++ b/src/ServerStat.cc
@@ -208,18 +208,16 @@ bool ServerStat::operator==(const ServerStat& serverStat) const
std::string ServerStat::toString() const
{
- std::string res;
- strappend(res, "host=", getHostname(), ", ");
- strappend(res, "protocol=", getProtocol(), ", ");
- strappend(res, "dl_speed=", util::uitos(getDownloadSpeed()), ", ");
- strappend(res, "sc_avg_speed=", util::uitos(getSingleConnectionAvgSpeed()),
- ", ");
- strappend(res, "mc_avg_speed=", util::uitos(getMultiConnectionAvgSpeed()),
- ", ");
- strappend(res, "last_updated=", util::itos(getLastUpdated().getTime()), ", ");
- strappend(res, "counter=", util::uitos(getCounter()), ", ");
- strappend(res, "status=", ServerStat::STATUS_STRING[getStatus()]);
- return res;
+ return fmt("host=%s, protocol=%s, dl_speed=%u, sc_avg_speed=%u,"
+ " mc_avg_speed=%u, last_updated=%ld, counter=%u, status=%s",
+ getHostname().c_str(),
+ getProtocol().c_str(),
+ getDownloadSpeed(),
+ getSingleConnectionAvgSpeed(),
+ getMultiConnectionAvgSpeed(),
+ getLastUpdated().getTime(),
+ getCounter(),
+ ServerStat::STATUS_STRING[getStatus()].c_str());
}
} // namespace aria2
diff --git a/src/a2functional.h b/src/a2functional.h
index 28b32ec6..9b5cab2d 100644
--- a/src/a2functional.h
+++ b/src/a2functional.h
@@ -283,63 +283,6 @@ std::string strjoin(InputIterator first, InputIterator last,
return result;
}
-template<typename T1, typename T2>
-inline void strappend(std::string& base, const T1& a1, const T2& a2)
-{
- base += a1; base += a2;
-}
-
-template<typename T1, typename T2, typename T3>
-inline void strappend(std::string& base,
- const T1& a1, const T2& a2, const T3& a3)
-{
- base += a1; base += a2; base += a3;
-}
-
-template<typename T1, typename T2, typename T3, typename T4>
-inline void strappend(std::string& base,
- const T1& a1, const T2& a2, const T3& a3, const T4& a4)
-{
- base += a1; base += a2; base += a3; base += a4;
-}
-
-template<typename T1, typename T2, typename T3, typename T4, typename T5>
-inline void strappend(std::string& base,
- const T1& a1, const T2& a2, const T3& a3, const T4& a4,
- const T5& a5)
-{
- base += a1; base += a2; base += a3; base += a4; base += a5;
-}
-
-template<typename T1, typename T2, typename T3, typename T4, typename T5,
- typename T6>
-inline void strappend(std::string& base,
- const T1& a1, const T2& a2, const T3& a3, const T4& a4,
- const T5& a5, const T6& a6)
-{
- base += a1; base += a2; base += a3; base += a4; base += a5; base += a6;
-}
-
-template<typename T1, typename T2, typename T3, typename T4, typename T5,
- typename T6, typename T7>
-inline void strappend(std::string& base,
- const T1& a1, const T2& a2, const T3& a3, const T4& a4,
- const T5& a5, const T6& a6, const T7& a7)
-{
- base += a1; base += a2; base += a3; base += a4; base += a5; base += a6;
- base += a7;
-}
-
-template<typename T1, typename T2, typename T3, typename T4, typename T5,
- typename T6, typename T7, typename T8>
-inline void strappend(std::string& base,
- const T1& a1, const T2& a2, const T3& a3, const T4& a4,
- const T5& a5, const T6& a6, const T7& a7, const T8& a8)
-{
- base += a1; base += a2; base += a3; base += a4; base += a5; base += a6;
- base += a7; base += a8;
-}
-
template<typename T>
class LeastRecentAccess:public std::binary_function<T, T, bool> {
public:
diff --git a/src/util.cc b/src/util.cc
index d923a20b..d6320beb 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1588,8 +1588,16 @@ void executeHook
}
cmdline += "/C \"";
}
- strappend(cmdline, "\"", command, "\"");
- strappend(cmdline, " ", gidStr, " ", numFilesStr, " \"", firstFilename, "\"");
+ cmdline += "\"";
+ cmdline += command;
+ cmdline += "\"";
+ cmdline += " ";
+ cmdline += gidStr;
+ cmdline += " ";
+ cmdline += numFilesStr;
+ cmdline += " \"";
+ cmdline += firstFilename;
+ cmdline += "\"";
if(batch) {
cmdline += "\"";
}