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

Function parse_hook_list

plugins/tcpinfo/tcpinfo.cc:274–313  ·  view source on GitHub ↗

Parse a comma-separated list of hook names into a hook bitmask.

Source from the content-addressed store, hash-verified

272
273// Parse a comma-separated list of hook names into a hook bitmask.
274static unsigned
275parse_hook_list(const char *hook_list)
276{
277 unsigned mask = 0;
278 char *tok;
279 char *str;
280 char *last;
281
282 const struct hookmask {
283 const char *name;
284 unsigned mask;
285 } hooks[] = {
286 {"ssn_start", TCPI_HOOK_SSN_START },
287 {"txn_start", TCPI_HOOK_TXN_START },
288 {"send_resp_hdr", TCPI_HOOK_SEND_RESPONSE},
289 {"txn_close", TCPI_HOOK_TXN_CLOSE },
290 {nullptr, 0u }
291 };
292
293 str = TSstrdup(hook_list);
294
295 for (tok = strtok_r(str, ",", &last); tok; tok = strtok_r(nullptr, ",", &last)) {
296 bool match = false;
297
298 for (const struct hookmask *m = hooks; m->name != nullptr; ++m) {
299 if (strcmp(m->name, tok) == 0) {
300 mask |= m->mask;
301 match = true;
302 break;
303 }
304 }
305
306 if (!match) {
307 TSError("[tcpinfo] invalid hook name '%s'", tok);
308 }
309 }
310
311 TSfree(str);
312 return mask;
313}
314
315void
316TSPluginInit(int argc, const char *argv[])

Callers 1

TSPluginInitFunction · 0.85

Calls 4

TSstrdupFunction · 0.85
strcmpFunction · 0.85
TSfreeFunction · 0.85
TSErrorFunction · 0.50

Tested by

no test coverage detected