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

Method preprocess

plugins/header_rewrite/parser.cc:156–238  ·  view source on GitHub ↗

This is the main "parser", a helper function to the above tokenizer. NOTE: this modifies (possibly) the tokens list, therefore, we pass in a copy of the parsers tokens here, such that the original token list is retained (useful for tests etc.).

Source from the content-addressed store, hash-verified

154// This is the main "parser", a helper function to the above tokenizer. NOTE: this modifies (possibly) the tokens list,
155// therefore, we pass in a copy of the parsers tokens here, such that the original token list is retained (useful for tests etc.).
156bool
157Parser::preprocess(std::vector<std::string> tokens)
158{
159 // The last token might be the "flags" section, lets consume it if it is
160 if (tokens.size() > 0) {
161 std::string m = tokens[tokens.size() - 1];
162
163 if (!m.empty() && (m[0] == '[')) {
164 if (m[m.size() - 1] == ']') {
165 m = m.substr(1, m.size() - 2);
166 if (m.find_first_of(',') != std::string::npos) {
167 std::istringstream iss(m);
168 std::string t;
169 while (getline(iss, t, ',')) {
170 _mods.push_back(t);
171 }
172 } else {
173 _mods.push_back(m);
174 }
175 tokens.pop_back(); // consume it, so we don't concatenate it into the value
176 } else {
177 // Syntax error
178 TSError("[%s] mods have to be enclosed in []", PLUGIN_NAME);
179 return false;
180 }
181 }
182 }
183
184 // Special case for "conditional" values
185 if (tokens[0].substr(0, 2) == "%{") {
186 _cond = true;
187 } else if (tokens[0] == "cond") {
188 _cond = true;
189 tokens.erase(tokens.begin());
190 } else if (tokens[0] == "else") {
191 _cond = false;
192 _else = true;
193
194 return true;
195 }
196
197 // Is it a condition or operator?
198 if (_cond) {
199 if ((tokens[0].substr(0, 2) == "%{") && (tokens[0][tokens[0].size() - 1] == '}')) {
200 _op = tokens[0].substr(2, tokens[0].size() - 3);
201 if (tokens.size() > 2 && (tokens[1][0] == '=' || tokens[1][0] == '>' || tokens[1][0] == '<')) {
202 // cond + [=<>] + argument
203 _arg = tokens[1] + tokens[2];
204 } else if (tokens.size() > 1) {
205 // This is for the regular expression, which for some reason has its own handling?? ToDo: Why ?
206 _arg = tokens[1];
207 } else {
208 // This would be for hook conditions, which has no argument.
209 _arg = "";
210 }
211 } else {
212 TSError("[%s] conditions must be embraced in %%{}", PLUGIN_NAME);
213 return false;

Callers

nothing calls this directly

Calls 9

pop_backMethod · 0.80
TSErrorFunction · 0.70
sizeMethod · 0.45
emptyMethod · 0.45
substrMethod · 0.45
push_backMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected