| 947 | } |
| 948 | |
| 949 | static config_t * |
| 950 | new_config(std::fstream &fh) |
| 951 | { |
| 952 | config_t *config = nullptr; |
| 953 | config = new config_t; |
| 954 | config->recordTypes = DEFAULT_RECORD_TYPES; |
| 955 | config->stats_path = ""; |
| 956 | std::string cur_line; |
| 957 | |
| 958 | if (!fh) { |
| 959 | Dbg(dbg_ctl, "No config file, using defaults"); |
| 960 | return config; |
| 961 | } |
| 962 | |
| 963 | while (std::getline(fh, cur_line)) { |
| 964 | swoc::TextView line{cur_line}; |
| 965 | if (line.ltrim_if(&isspace).empty() || '#' == *line) { |
| 966 | continue; /* # Comments, only at line beginning */ |
| 967 | } |
| 968 | |
| 969 | size_t p = 0; |
| 970 | |
| 971 | static constexpr swoc::TextView PATH_TAG = "path="; |
| 972 | static constexpr swoc::TextView RECORD_TAG = "record_types="; |
| 973 | static constexpr swoc::TextView ADDR_TAG = "allow_ip="; |
| 974 | static constexpr swoc::TextView ADDR6_TAG = "allow_ip6="; |
| 975 | |
| 976 | if ((p = line.find(PATH_TAG)) != std::string::npos) { |
| 977 | line.remove_prefix(p + PATH_TAG.size()).ltrim('/'); |
| 978 | Dbg(dbg_ctl, "parsing path"); |
| 979 | config->stats_path = line; |
| 980 | } else if ((p = line.find(RECORD_TAG)) != std::string::npos) { |
| 981 | Dbg(dbg_ctl, "parsing record types"); |
| 982 | line.remove_prefix(p).remove_prefix(RECORD_TAG.size()); |
| 983 | config->recordTypes = swoc::svtou(line, nullptr, 16); |
| 984 | } else if ((p = line.find(ADDR_TAG)) != std::string::npos) { |
| 985 | parseIpMap(config, line.remove_prefix(p).remove_prefix(ADDR_TAG.size())); |
| 986 | } else if ((p = line.find(ADDR6_TAG)) != std::string::npos) { |
| 987 | parseIpMap(config, line.remove_prefix(p).remove_prefix(ADDR6_TAG.size())); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | if (config->addrs.count() == 0) { |
| 992 | Dbg(dbg_ctl, "empty ip map found, setting defaults"); |
| 993 | parseIpMap(config, nullptr); |
| 994 | } |
| 995 | |
| 996 | Dbg(dbg_ctl, "config path=%s", config->stats_path.c_str()); |
| 997 | |
| 998 | return config; |
| 999 | } |
| 1000 | |
| 1001 | static void |
| 1002 | delete_config(config_t *config) |
no test coverage detected