| 680 | } |
| 681 | |
| 682 | XMLDocumentPtr ConfigProcessor::parseConfig(const std::string & config_path, Poco::XML::DOMParser & dom_parser) |
| 683 | { |
| 684 | fs::path p(config_path); |
| 685 | std::string extension = p.extension(); |
| 686 | boost::algorithm::to_lower(extension); |
| 687 | |
| 688 | if (extension == ".xml") |
| 689 | return dom_parser.parse(config_path); |
| 690 | if (extension == ".yaml" || extension == ".yml") |
| 691 | return YAMLParser::parse(config_path); |
| 692 | |
| 693 | /// Suppose non regular file parsed as XML, such as pipe: /dev/fd/X (regardless it has .xml extension or not) |
| 694 | if (!fs::is_regular_file(config_path)) |
| 695 | return dom_parser.parse(config_path); |
| 696 | |
| 697 | /// If the regular file begins with < it might be XML, otherwise it might be YAML. |
| 698 | bool maybe_xml = false; |
| 699 | { |
| 700 | std::ifstream file(config_path); |
| 701 | if (!file.is_open()) |
| 702 | throw Exception(ErrorCodes::CANNOT_LOAD_CONFIG, "Unknown format of '{}' config", config_path); |
| 703 | |
| 704 | std::string line; |
| 705 | while (std::getline(file, line)) |
| 706 | { |
| 707 | const size_t pos = firstNonWhitespacePos(line); |
| 708 | |
| 709 | if (pos < line.size() && '<' == line[pos]) |
| 710 | { |
| 711 | maybe_xml = true; |
| 712 | break; |
| 713 | } |
| 714 | if (pos != std::string::npos) |
| 715 | break; |
| 716 | } |
| 717 | } |
| 718 | if (maybe_xml) |
| 719 | return dom_parser.parse(config_path); |
| 720 | return YAMLParser::parse(config_path); |
| 721 | } |
| 722 | |
| 723 | XMLDocumentPtr ConfigProcessor::processConfig( |
| 724 | bool * has_zk_includes, |
nothing calls this directly
no test coverage detected