302
309
std::string out_;
313
const char* get_conf(const T& c, const std::string& v)
315
typename T::const_iterator i = c.find(v);
316
return i == c.end() ? NULL : i->second.c_str();
319
void connection_c::read_conf_files()
323
vector<string> conf_files;
326
boost::array<char, MAX_PATH> d;
327
GetWindowsDirectoryA(d.data(), d.size());
328
conf_files.push_back(string(d.data()) + "/my.cnf");
329
conf_files.push_back(string(d.data()) + "/drizzle.cnf");
330
conf_files.push_back(string(d.data()) + "/drizzle.conf");
333
conf_files.push_back("/etc/mysql/my.cnf");
334
conf_files.push_back("/etc/drizzle/drizzle.cnf");
335
conf_files.push_back("/etc/drizzle/drizzle.conf");
337
if (const char* d = getenv("HOME"))
339
conf_files.push_back(string(d) + "/.my.cnf");
340
conf_files.push_back(string(d) + "/.drizzle.conf");
343
typedef map<string, string> conf_t;
345
BOOST_FOREACH(string& it, conf_files)
347
ifstream is(it.c_str());
348
bool client_section = false;
349
for (string s; getline(is, s); )
351
size_t i = s.find('#');
352
if (i != string::npos)
355
if (boost::starts_with(s, "["))
357
client_section = s == "[client]";
360
else if (!client_section)
363
if (i == string::npos)
365
conf[boost::trim_copy(s.substr(0, i))] = boost::trim_copy(s.substr(i + 1));
366
if (s.empty() || !client_section)
370
if (conf.count("host") || conf.count("port"))
371
set_tcp(get_conf(conf, "host"), atoi(get_conf(conf, "port")));
372
if (conf.count("user") || conf.count("password"))
373
set_auth(get_conf(conf, "user"), get_conf(conf, "password"));