24 int CurlConfig::parseConfig(
CurlConfig & config,
const std::string & filename)
31 char *home = getenv(
"HOME");
33 curlrcFile = string( home ) + string(
"/.curlrc" );
36 curlrcFile = filename;
38 PathInfo h_info(curlrcFile.dirname(), PathInfo::LSTAT);
39 PathInfo c_info(curlrcFile, PathInfo::LSTAT);
41 if( h_info.isDir() && h_info.userMayRX() &&
42 c_info.isFile() && c_info.userMayR() )
44 MIL <<
"Going to parse " << curlrcFile << endl;
49 WAR <<
"Not allowed to parse '" << curlrcFile
50 <<
"': dir/file owner: " << h_info.owner() <<
"/" << c_info.owner()
51 <<
", process uid: " << getuid()
52 <<
" (" << (!getlogin_r(buf, 31) ? buf :
"") <<
")" << std::endl;
57 ifstream inp(curlrcFile.c_str());
78 const char * beg = line.c_str();
79 const char * cur = beg;
82 #define ISSEP(x) (((x)=='=') || ((x) == ':') || isspace(x))
85 while (*cur && *cur ==
'-')
90 while (*cur && !
ISSEP(*cur))
93 string option(beg, cur - beg);
96 while (*cur &&
ISSEP(*cur))
104 string value(beg, cur - beg);
106 DBG <<
"GOT: " << option << endl;
111 if (value[0] ==
'\"')
116 pos == value.size() - 1 && pos > 1 && value[pos-1] !=
'\\';
117 value = value.substr(1,
118 cut_last ? value.size() - 2 : value.size() - 1);
122 while ((pos = value.find(
'\\', pos)) != string::npos)
125 if (pos == value.size() - 1)
127 value = value.erase(pos, 1);
134 value = value.replace(pos, 2,
"\t");
137 value = value.replace(pos, 2,
"\n");
140 value = value.replace(pos, 2,
"\r");
143 value = value.replace(pos, 2,
"\v");
146 value = value.erase(pos++, 1);
149 value = value.erase(pos, 1);
157 CurlConfig::setParameter(config, option, value);
170 const std::string & option,
171 const std::string & value)
173 if (option ==
"proxy-user")
178 DBG <<
"Ignoring option " << option << endl;
bool next()
Advance to next line.
Simple lineparser: Traverse each line in a file.
std::string trim(const std::string &s, const Trim trim_r)