Restrict `detected` to the comma-separated token list. Returns false (after * printing the vocabulary) when a token is unknown, so a typo can never be * mistaken for "that client was not installed". */
| 9330 | * printing the vocabulary) when a token is unknown, so a typo can never be |
| 9331 | * mistaken for "that client was not installed". */ |
| 9332 | static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) { |
| 9333 | bool wanted[CLI_CLIENT_COUNT]; |
| 9334 | memset(wanted, 0, sizeof(wanted)); |
| 9335 | char buf[CLI_BUF_1K]; |
| 9336 | snprintf(buf, sizeof(buf), "%s", spec ? spec : ""); |
| 9337 | char *save = NULL; |
| 9338 | for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) { |
| 9339 | while (*tok == ' ') { |
| 9340 | tok++; |
| 9341 | } |
| 9342 | size_t len = strlen(tok); |
| 9343 | while (len > 0 && tok[len - 1] == ' ') { |
| 9344 | tok[--len] = '\0'; |
| 9345 | } |
| 9346 | if (!tok[0]) { |
| 9347 | continue; |
| 9348 | } |
| 9349 | bool matched = false; |
| 9350 | for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) { |
| 9351 | if (strcmp(tok, CLI_CLIENTS[i].token) == 0) { |
| 9352 | wanted[i] = true; |
| 9353 | matched = true; |
| 9354 | break; |
| 9355 | } |
| 9356 | } |
| 9357 | if (!matched) { |
| 9358 | (void)fprintf(stderr, "error: unknown client: %s\n\n", tok); |
| 9359 | cli_clients_print_list(stderr); |
| 9360 | return false; |
| 9361 | } |
| 9362 | } |
| 9363 | for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) { |
| 9364 | if (!wanted[i]) { |
| 9365 | *(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false; |
| 9366 | } |
| 9367 | } |
| 9368 | return true; |
| 9369 | } |
| 9370 | |
| 9371 | #ifdef CBM_CLI_ENABLE_TEST_API |
| 9372 | bool cbm_cli_clients_apply_selection_for_testing(const char *spec, |
no test coverage detected