Parse a comma-separated list of hook names into a hook bitmask.
| 272 | |
| 273 | // Parse a comma-separated list of hook names into a hook bitmask. |
| 274 | static unsigned |
| 275 | parse_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 | |
| 315 | void |
| 316 | TSPluginInit(int argc, const char *argv[]) |
no test coverage detected