MCPcopy Create free account
hub / github.com/apache/trafficserver / new_config

Function new_config

plugins/stats_over_http/stats_over_http.cc:949–999  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

947}
948
949static config_t *
950new_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
1001static void
1002delete_config(config_t *config)

Callers 1

load_config_fileFunction · 0.85

Calls 8

svtouFunction · 0.85
parseIpMapFunction · 0.85
emptyMethod · 0.45
findMethod · 0.45
remove_prefixMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected