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

Function loadRegionMap

plugins/origin_server_auth/origin_server_auth.cc:84–146  ·  view source on GitHub ↗

* @brief a helper function which loads the entry-point to region from files. * @param args classname + filename in ' : ' format. * @return true if successful, false otherwise. */

Source from the content-addressed store, hash-verified

82 * @return true if successful, false otherwise.
83 */
84static bool
85loadRegionMap(StringMap &m, const String &filename)
86{
87 static const char *EXPECTED_FORMAT = "<s3-entry-point>:<s3-region>";
88
89 String path(makeConfigPath(filename));
90
91 std::ifstream ifstr;
92 String line;
93
94 ifstr.open(path.c_str());
95 if (!ifstr) {
96 TSError("[%s] failed to load s3-region map from '%s'", PLUGIN_NAME, path.c_str());
97 return false;
98 }
99
100 Dbg(dbg_ctl, "loading region mapping from '%s'", path.c_str());
101
102 m[""] = ""; /* set a default just in case if the user does not specify it */
103
104 while (std::getline(ifstr, line)) {
105 String::size_type pos;
106
107 // Allow #-prefixed comments.
108 pos = line.find_first_of('#');
109 if (pos != String::npos) {
110 line.resize(pos);
111 }
112
113 if (line.empty()) {
114 continue;
115 }
116
117 std::size_t d = line.find(':');
118 if (String::npos == d) {
119 TSError("[%s] failed to parse region map string '%s', expected format: '%s'", PLUGIN_NAME, line.c_str(), EXPECTED_FORMAT);
120 return false;
121 }
122
123 String entrypoint(trimWhiteSpaces(String(line, 0, d)));
124 String region(trimWhiteSpaces(String(line, d + 1, String::npos)));
125
126 if (region.empty()) {
127 Dbg(dbg_ctl, "<s3-region> in '%s' cannot be empty (skipped), expected format: '%s'", line.c_str(), EXPECTED_FORMAT);
128 continue;
129 }
130
131 if (entrypoint.empty()) {
132 Dbg(dbg_ctl, "added default region %s", region.c_str());
133 } else {
134 Dbg(dbg_ctl, "added entry-point:%s, region:%s", entrypoint.c_str(), region.c_str());
135 }
136
137 m[entrypoint] = region;
138 }
139
140 if (m.at("").empty()) {
141 Dbg(dbg_ctl, "default region was not defined");

Callers 1

set_region_mapMethod · 0.85

Calls 10

trimWhiteSpacesFunction · 0.85
makeConfigPathFunction · 0.70
TSErrorFunction · 0.50
StringClass · 0.50
openMethod · 0.45
c_strMethod · 0.45
resizeMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected