From 48175dcb3ab1b0f8ec76f6b523c0fc18c5b93296 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 12 Nov 2009 15:07:18 +0000 Subject: [PATCH] 2009-11-13 Tatsuhiro Tsujikawa Code cleanup * src/Request.cc * src/Request.h --- ChangeLog | 6 +++++ src/Request.cc | 52 +++++++++++++++++++++---------------------- src/Request.h | 60 ++++++++++++++++++++++++-------------------------- 3 files changed, 61 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a933c0f..5b4d112b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-11-13 Tatsuhiro Tsujikawa + + Code cleanup + * src/Request.cc + * src/Request.h + 2009-11-12 Tatsuhiro Tsujikawa Rewritten Request::parseUrl() diff --git a/src/Request.cc b/src/Request.cc index 6954ba23..2fbeea2e 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -56,18 +56,18 @@ const std::string Request::PROTO_HTTPS("https"); const std::string Request::PROTO_FTP("ftp"); Request::Request(): - port(0), tryCount(0), + _port(0), _tryCount(0), _redirectCount(0), _supportsPersistentConnection(true), _keepAliveHint(false), _pipeliningHint(false), _maxPipelinedRequest(1), - method(METHOD_GET), + _method(METHOD_GET), _hasPassword(false), _ipv6LiteralAddress(false) {} -static std::string removeFragment(const std::string url) +static std::string removeFragment(const std::string& url) { std::string::size_type sharpIndex = url.find("#"); if(sharpIndex == std::string::npos) { @@ -109,23 +109,23 @@ static std::string urlencode(const std::string& src) bool Request::setUrl(const std::string& url) { _supportsPersistentConnection = true; - this->url = url; - return parseUrl(urlencode(removeFragment(url))); + _url = url; + return parseUrl(urlencode(removeFragment(_url))); } bool Request::resetUrl() { - previousUrl = referer; + _previousUrl = _referer; _supportsPersistentConnection = true; - return parseUrl(urlencode(removeFragment(url))); + return parseUrl(urlencode(removeFragment(_url))); } void Request::setReferer(const std::string& url) { - referer = previousUrl = urlencode(removeFragment(url)); + _referer = _previousUrl = urlencode(removeFragment(url)); } bool Request::redirectUrl(const std::string& url) { - previousUrl = A2STR::NIL; + _previousUrl = A2STR::NIL; _supportsPersistentConnection = true; ++_redirectCount; if(url.find("://") == std::string::npos) { @@ -133,10 +133,10 @@ bool Request::redirectUrl(const std::string& url) { // field, but some servers don't obey this rule. if(util::startsWith(url, "/")) { // abosulute path - return parseUrl(strconcat(protocol, "://", host, url)); + return parseUrl(strconcat(_protocol, "://", _host, url)); } else { // relative path - return parseUrl(strconcat(protocol, "://", host, dir, "/", url)); + return parseUrl(strconcat(_protocol, "://", _host, _dir, "/", url)); } } else { return parseUrl(url); @@ -144,11 +144,11 @@ bool Request::redirectUrl(const std::string& url) { } bool Request::parseUrl(const std::string& url) { - currentUrl = url; - host = A2STR::NIL; - port = 0; - dir = A2STR::NIL; - file = A2STR::NIL; + _currentUrl = url; + _host = A2STR::NIL; + _port = 0; + _dir = A2STR::NIL; + _file = A2STR::NIL; _query = A2STR::NIL; _username = A2STR::NIL; _password = A2STR::NIL; @@ -178,9 +178,9 @@ bool Request::parseUrl(const std::string& url) { // find protocol std::string::size_type protocolOffset = url.find("://"); if(protocolOffset == std::string::npos) return false; - protocol = std::string(url.begin(), url.begin()+protocolOffset); + _protocol = std::string(url.begin(), url.begin()+protocolOffset); uint16_t defPort; - if((defPort = FeatureConfig::getInstance()->getDefaultPort(protocol)) == 0) { + if((defPort = FeatureConfig::getInstance()->getDefaultPort(_protocol)) == 0) { return false; } // find authority @@ -250,7 +250,7 @@ bool Request::parseUrl(const std::string& url) { if(portFirst == authorityLast) { // If port is not specified, then we set it to default port of // its protocol.. - port = defPort; + _port = defPort; } else { try { unsigned int tempPort = @@ -258,15 +258,15 @@ bool Request::parseUrl(const std::string& url) { if(65535 < tempPort) { return false; } - port = tempPort; + _port = tempPort; } catch(RecoverableException& e) { return false; } } if(_ipv6LiteralAddress) { - host = std::string(hostPortFirst+1, hostLast-1); + _host = std::string(hostPortFirst+1, hostLast-1); } else { - host = std::string(hostPortFirst, hostLast); + _host = std::string(hostPortFirst, hostLast); } // find directory and file part std::string::const_iterator dirLast = authorityLast; @@ -277,7 +277,7 @@ bool Request::parseUrl(const std::string& url) { } } if(dirLast != queryFirst) { - file = std::string(dirLast+1, queryFirst); + _file = std::string(dirLast+1, queryFirst); } // Erase duplicated slashes. std::string::const_iterator dirFirst = authorityLast; @@ -294,9 +294,9 @@ bool Request::parseUrl(const std::string& url) { } } if(dirFirst == dirLast) { - dir = A2STR::SLASH_C; + _dir = A2STR::SLASH_C; } else { - dir = std::string(dirFirst, dirLast); + _dir = std::string(dirFirst, dirLast); } return true; } @@ -313,7 +313,7 @@ void Request::setMaxPipelinedRequest(unsigned int num) const SharedHandle& Request::initPeerStat() { - _peerStat.reset(new PeerStat(0, host, protocol)); + _peerStat.reset(new PeerStat(0, _host, _protocol)); return _peerStat; } diff --git a/src/Request.h b/src/Request.h index c9e6b86c..48a3b928 100644 --- a/src/Request.h +++ b/src/Request.h @@ -47,24 +47,24 @@ namespace aria2 { class Request { private: - std::string url; - std::string currentUrl; + std::string _url; + std::string _currentUrl; /** * URL previously requested to the server. This is used as Referer */ - std::string previousUrl; + std::string _previousUrl; /** * URL used as Referer in the initial request */ - std::string referer; - std::string protocol; - std::string host; - uint16_t port; - std::string dir; - std::string file; + std::string _referer; + std::string _protocol; + std::string _host; + uint16_t _port; + std::string _dir; + std::string _file; /* after ? mark(includes '?' itself) */ std::string _query; - unsigned int tryCount; + unsigned int _tryCount; unsigned int _redirectCount; @@ -77,7 +77,7 @@ private: // maximum number of pipelined requests unsigned int _maxPipelinedRequest; - std::string method; + std::string _method; std::string _username; @@ -93,18 +93,16 @@ private: public: Request(); - // Parses URL and sets url, host, port, dir, file fields. - // Returns true if parsing goes successful, otherwise returns false. + // Sets url to _url and parses URL. Returns true if parsing goes + // successful, otherwise returns false. bool setUrl(const std::string& url); - // Parses URL and sets host, port, dir, file fields. - // url field are not altered by this method. - // Returns true if parsing goes successful, otherwise returns false. + // Parses URL. _url field are not altered by this method. Returns + // true if parsing goes successful, otherwise returns false. bool redirectUrl(const std::string& url); bool resetUrl(); - void resetTryCount() { tryCount = 0; } - void addTryCount() { ++tryCount; } - unsigned int getTryCount() const { return tryCount; } - //bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; } + void resetTryCount() { _tryCount = 0; } + void addTryCount() { ++_tryCount; } + unsigned int getTryCount() const { return _tryCount; } void resetRedirectCount(); @@ -114,13 +112,13 @@ public: } // Returns URI passed by setUrl() - const std::string& getUrl() const { return url; } - const std::string& getCurrentUrl() const { return currentUrl; } - const std::string& getPreviousUrl() const { return previousUrl; } - const std::string& getReferer() const { return referer; } + const std::string& getUrl() const { return _url; } + const std::string& getCurrentUrl() const { return _currentUrl; } + const std::string& getPreviousUrl() const { return _previousUrl; } + const std::string& getReferer() const { return _referer; } void setReferer(const std::string& url); - const std::string& getProtocol() const { return protocol; } - const std::string& getHost() const { return host; } + const std::string& getProtocol() const { return _protocol; } + const std::string& getHost() const { return _host; } // Same as getHost(), but for IPv6 literal addresses, enclose them // with square brackets and return. std::string getURIHost() const @@ -131,9 +129,9 @@ public: return getHost(); } } - uint16_t getPort() const { return port; } - const std::string& getDir() const { return dir; } - const std::string& getFile() const { return file;} + uint16_t getPort() const { return _port; } + const std::string& getDir() const { return _dir; } + const std::string& getFile() const { return _file;} const std::string& getQuery() const { return _query; } bool isIPv6LiteralAddress() const { return _ipv6LiteralAddress; } @@ -180,7 +178,7 @@ public: } void setMethod(const std::string& method) { - this->method = method; + _method = method; } const std::string& getUsername() const @@ -200,7 +198,7 @@ public: } const std::string& getMethod() const { - return method; + return _method; } const SharedHandle& getPeerStat() const { return _peerStat; }