diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-03-18 15:42:34 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-03-18 15:42:34 +0000 |
| commit | 7ff627079f6ed776dea1ce6fede1c1a07ef7f288 (patch) | |
| tree | 8f7b7e5b763dc3841df03928fe2aa50abd35a810 /src/Netrc.cc | |
| parent | 58d4dde223e815b75a3bf6bfbd4169818faca3bd (diff) | |
2007-03-19 Tatsuhiro Tsujikawa <tujikawa at valkyrie dot rednoah com>
To integrate Netrc into exsiting classes:
* src/Request.h
(_userDefinedAuthConfig): New variable.
(findNetrcAuthenticator): New function.
(segment): Removed.
(setUserDefinedAuthConfig): New function.
(resolveHttpAuthConfigItem): New function.
(resolveFtpAuthConfigItem): New function.
(resolveHttpProxyAuthConfigItem): New function.
* src/HttpRequest.h
(authConfig): Removed.
(proxyAuthConfig): Removed.
(setAuthConfig): Removed.
(setProxyAuthConfig): Removed.
* src/UrlRequest.h
(getHeadResult): Added a parameter: authConfigHandle
* src/common.h
(SingletonHolder.h): New include.
* src/main.cc
(Netrc.h): New include.
(main): Removed initial values of PREF_FTP_USER,
PREF_FTP_PASSWD.
Added initial value of PREF_NETRC_PATH.
Added the initialization of netrc.
* src/AuthConfig.h: New class.
* src/prefs.h
(PREF_NETRC_PATH): New definition.
* src/HttpAuthConfig.h: Removed.
* src/Netrc.cc
(getRequiredNextToken): New function.
(skipMacdef): New function.
(parse): Rewritten.
* src/Netrc.h
(getRequiredNextToken): New function.
(skipMacdef): New function.
* src/Util.h, src/Util.cc
(getHomeDir): New function.
* src/TrackerWatcherComand.cc
(createRequestCommand): Use AuthConfig.
* src/FtpConnection.cc
(sendUser): Use Request::resolveFtpAuthConfigItem().
(sendPass): Use Request::resolveFtpAuthConfigItem().
* src/Request.cc
(findNetrcAuthenticator): New function.
(resolveHttpAuthConfigItem): New function.
(resolveFtpAuthConfigItem): New function.
(resolveHttpProxyAuthConfigItem): New function.
* src/UrlRequestInfo.cc: Use AuthConfig.
* src/HttpRequest.cc
(createRequest): Use authConfig.
(getProxyAuthString): Use authConfig.
(configure): Removed PREF_HTTP_USER, PREF_HTTP_PASSWD,
PREF_HTTP_PROXY_USER, PREF_HTTP_PROXY_PASSWD.
Diffstat (limited to 'src/Netrc.cc')
| -rw-r--r-- | src/Netrc.cc | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/src/Netrc.cc b/src/Netrc.cc index a30e8485..4538f526 100644 --- a/src/Netrc.cc +++ b/src/Netrc.cc @@ -37,6 +37,27 @@ #include "RecoverableException.h" #include <fstream> +string Netrc::getRequiredNextToken(ifstream& f) const +{ + string token; + if(f >> token) { + return token; + } else { + throw new RecoverableException("Netrc:parse error. EOF reached where a token expected."); + } +} + +void Netrc::skipMacdef(ifstream& f) const +{ + string line; + getline(f, line); + while(getline(f, line)) { + if(line == "\r" || line == "") { + break; + } + } +} + void Netrc::parse(const string& path) { authenticators.clear(); @@ -46,32 +67,29 @@ void Netrc::parse(const string& path) throw new RecoverableException("File not found: %s", path.c_str()); } - int32_t lineNum = 0; - string line; AuthenticatorHandle authenticator = 0; - while(getline(f, line)) { - ++lineNum; - if(Util::trim(line).empty()) { - continue; - } - pair<string, string> nameValuePair = Util::split(line, "\r\n\t "); - if(nameValuePair.first == "machine") { + string token; + while(f >> token) { + if(token == "machine") { storeAuthenticator(authenticator); authenticator = new Authenticator(); - authenticator->setMachine(nameValuePair.second); - } else if(nameValuePair.first == "default") { + authenticator->setMachine(getRequiredNextToken(f)); + } else if(token == "default") { storeAuthenticator(authenticator); authenticator = new DefaultAuthenticator(); } else { if(authenticator.isNull()) { - throw new RecoverableException("Malformed netrc file: line %d", lineNum); + throw new RecoverableException("Netrc:parse error. %s encounterd where 'machine' or 'default' expected."); } - if(nameValuePair.first == "login") { - authenticator->setLogin(nameValuePair.second); - } else if(nameValuePair.first == "password") { - authenticator->setPassword(nameValuePair.second); - } else if(nameValuePair.first == "account") { - authenticator->setAccount(nameValuePair.second); + if(token == "login") { + authenticator->setLogin(getRequiredNextToken(f)); + } else if(token == "password") { + authenticator->setPassword(getRequiredNextToken(f)); + } else if(token == "account") { + authenticator->setAccount(getRequiredNextToken(f)); + } else if(token == "macdef") { + getRequiredNextToken(f); + skipMacdef(f); } } } |
