diff options
author | Johannes Winkelmann <jw@smts.ch> | 2006-02-23 14:18:42 +0000 |
---|---|---|
committer | Johannes Winkelmann <jw@smts.ch> | 2006-02-23 14:18:42 +0000 |
commit | b103cf5e680227d5214faba552fd6be8367a00aa (patch) | |
tree | 291fddef8614ca8e2d7076c194c2c83d4f54a0a9 /configparser.cpp | |
parent | 18c22c5a414a8beeac0d958ab39589c883ab06d4 (diff) | |
download | httpup-b103cf5e680227d5214faba552fd6be8367a00aa.tar.gz httpup-b103cf5e680227d5214faba552fd6be8367a00aa.tar.xz |
httpup: sync with bzr repo (0.4.0g)
Diffstat (limited to 'configparser.cpp')
-rw-r--r-- | configparser.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/configparser.cpp b/configparser.cpp index bee5cf0..f6af600 100644 --- a/configparser.cpp +++ b/configparser.cpp @@ -3,10 +3,10 @@ // AUTHOR: Johannes Winkelmann, jw@tks6.net // COPYRIGHT: (c) 2002-2005 by Johannes Winkelmann // --------------------------------------------------------------------- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. //////////////////////////////////////////////////////////////////////// #include <iostream> @@ -21,37 +21,44 @@ int ConfigParser::parseConfig(const std::string& fileName, if (!fp) { return -1; } - + char line[512]; string s; while (fgets(line, 512, fp)) { if (line[strlen(line)-1] == '\n') { line[strlen(line)-1] = '\0'; - } + } s = line; - + + // strip comments string::size_type pos = s.find("#"); if (pos != string::npos) { s = s.substr(0, pos); } - if (s.length() > 10) { - string key = s.substr(0, 10); - string val = stripWhiteSpace(s.substr(10)); + // whitespace separates + pos = s.find(' '); + if (pos == string::npos) { + pos = s.find('\t'); + } + if (pos != string::npos) { + string key = s.substr(0, pos); + string val = stripWhiteSpace(s.substr(pos)); if (key == "proxy_host") { config.proxyHost = val; - } else if (s.substr(0, 10) == "proxy_port") { + } else if (key == "proxy_port") { config.proxyPort = val; - } else if (s.substr(0, 10) == "proxy_user") { + } else if (key == "proxy_user") { config.proxyUser = val; - } else if (s.substr(0, 10) == "proxy_pass") { + } else if (key == "proxy_pass") { config.proxyPassword = val; + } else if (key == "operation_timeout") { + config.operationTimeout = val; } } - } - + fclose(fp); return 0; } @@ -65,6 +72,6 @@ string ConfigParser::stripWhiteSpace(const string& input) while (isspace(output[output.length()-1])) { output = output.substr(0, output.length()-1); } - + return output; } |