| 634 | } |
| 635 | |
| 636 | swoc::Errata |
| 637 | IpAllow::YAMLLoadCategoryDefinition(const YAML::Node &entry) |
| 638 | { |
| 639 | /* Parse this into ip_category_map: |
| 640 | * |
| 641 | * - name: <category name> |
| 642 | * ip_addrs: |
| 643 | * - <ip range> |
| 644 | * - <ip range> |
| 645 | * - <ip range> |
| 646 | */ |
| 647 | if (!entry.IsMap()) { |
| 648 | return swoc::Errata(ERRATA_ERROR, "{} {} - Category definition must be a map.", this, entry.Mark()); |
| 649 | } |
| 650 | |
| 651 | if (auto name_node = entry[YAML_TAG_CATEGORY_NAME]; name_node) { |
| 652 | if (!name_node.IsScalar()) { |
| 653 | return swoc::Errata(ERRATA_ERROR, "{} {} - Category name must be a string.", this, name_node.Mark()); |
| 654 | } |
| 655 | std::string const &name(name_node.Scalar()); |
| 656 | if (auto ip_addrs_node = entry[YAML_TAG_CATEGORY_IP_ADDRS]; ip_addrs_node) { |
| 657 | if (ip_addrs_node.IsSequence()) { |
| 658 | for (auto const &ip_addr_node : ip_addrs_node) { |
| 659 | if (auto errata = this->YAMLLoadCategoryIpRange(ip_addr_node, ip_category_map[name]); !errata.is_ok()) { |
| 660 | errata.note(R"(In category definition at {})", entry.Mark()); |
| 661 | return errata; |
| 662 | } |
| 663 | } |
| 664 | } else { |
| 665 | if (auto errata = this->YAMLLoadCategoryIpRange(ip_addrs_node, ip_category_map[name]); !errata.is_ok()) { |
| 666 | errata.note(R"(In category definition at {})", entry.Mark()); |
| 667 | return errata; |
| 668 | } |
| 669 | } |
| 670 | } else { // No ip_addrs. |
| 671 | return swoc::Errata(ERRATA_ERROR, "{} {} - IP Addresses must be specified.", this, entry.Mark()); |
| 672 | } |
| 673 | } else { // No name |
| 674 | return swoc::Errata(ERRATA_ERROR, "{} {} - Category name must be specified.", this, entry.Mark()); |
| 675 | } |
| 676 | return {}; |
| 677 | } |
| 678 | |
| 679 | swoc::Errata |
| 680 | IpAllow::YAMLLoadCategoryIpRange(const YAML::Node &node, swoc::IPSpace<bool> &space) |
no test coverage detected