Browse Source

Removed strappend

Tatsuhiro Tsujikawa 14 years ago
parent
commit
0da2468d6b

+ 6 - 11
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;
 }

+ 2 - 1
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;

+ 26 - 15
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;
 }
 

+ 19 - 14
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;

+ 9 - 7
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

+ 20 - 10
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);
     }
   }

+ 1 - 2
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()

+ 10 - 12
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

+ 0 - 57
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:

+ 10 - 2
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 += "\"";
   }

+ 1 - 1
test/PeerTest.cc

@@ -43,7 +43,7 @@ void PeerTest::testAmAllowedIndexSet() {
 }
 
 void PeerTest::testGetId() {
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost:6969"), peer->getID());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost(6969)"), peer->getID());
 }
 
 void PeerTest::testOperatorEqual()

+ 0 - 9
test/a2functionalTest.cc

@@ -14,14 +14,12 @@ class a2functionalTest:public CppUnit::TestFixture {
   CPPUNIT_TEST(testMemFunSh);
   CPPUNIT_TEST(testAdopt2nd);
   CPPUNIT_TEST(testStrjoin);
-  CPPUNIT_TEST(testStrappend);
   CPPUNIT_TEST(testLeastRecentAccess);
   CPPUNIT_TEST_SUITE_END();
 public:
   void testMemFunSh();
   void testAdopt2nd();
   void testStrjoin();
-  void testStrappend();
   void testLeastRecentAccess();
 
   class Greeting {
@@ -98,13 +96,6 @@ void a2functionalTest::testStrjoin()
                        strjoin(v.begin(), v.end(), " "));
 }
 
-void a2functionalTest::testStrappend()
-{
-  std::string str = "X=";
-  strappend(str, "3", ",Y=", "5");
-  CPPUNIT_ASSERT_EQUAL(std::string("X=3,Y=5"), str);
-}
-
 void a2functionalTest::testLeastRecentAccess()
 {
   std::vector<LastAccess> v;