| 292 | } |
| 293 | |
| 294 | Configuration * |
| 295 | Configuration::Parse(const char *path) |
| 296 | { |
| 297 | string pathstring(path); |
| 298 | |
| 299 | // If we have a path and it's not an absolute path, make it relative to the |
| 300 | // configuration directory. |
| 301 | if (!pathstring.empty() && pathstring[0] != '/') { |
| 302 | pathstring.assign(TSConfigDirGet()); |
| 303 | pathstring.append("/"); |
| 304 | pathstring.append(path); |
| 305 | } |
| 306 | |
| 307 | trim_if(pathstring, isspace); |
| 308 | |
| 309 | Configuration *c = new Configuration(); |
| 310 | HostConfiguration *current_host_configuration = new HostConfiguration(""); |
| 311 | |
| 312 | c->add_host_configuration(current_host_configuration); |
| 313 | |
| 314 | if (pathstring.empty()) { |
| 315 | return c; |
| 316 | } |
| 317 | |
| 318 | path = pathstring.c_str(); |
| 319 | info("Parsing file \"%s\"", path); |
| 320 | std::ifstream f; |
| 321 | |
| 322 | size_t lineno = 0; |
| 323 | |
| 324 | f.open(path, std::ios::in); |
| 325 | |
| 326 | if (!f.is_open()) { |
| 327 | warning("could not open file [%s], skip", path); |
| 328 | return c; |
| 329 | } |
| 330 | |
| 331 | enum ParserState state = kParseStart; |
| 332 | |
| 333 | while (!f.eof()) { |
| 334 | std::string line; |
| 335 | getline(f, line); |
| 336 | ++lineno; |
| 337 | |
| 338 | trim_if(line, isspace); |
| 339 | if (line.empty()) { |
| 340 | continue; |
| 341 | } |
| 342 | |
| 343 | for (;;) { |
| 344 | string token = extractFirstToken(line, isspace); |
| 345 | |
| 346 | if (token.empty()) { |
| 347 | break; |
| 348 | } |
| 349 | |
| 350 | // once a comment is encountered, we are done processing the line |
| 351 | if (token[0] == '#') { |
nothing calls this directly
no test coverage detected