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". */
| 9557 | * printing the vocabulary) when a token is unknown, so a typo can never be |
| 9558 | * mistaken for "that client was not installed". */ |
| 9559 | static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) { |
| 9560 | bool wanted[CLI_CLIENT_COUNT]; |
| 9561 | memset(wanted, 0, sizeof(wanted)); |
| 9562 | char buf[CLI_BUF_1K]; |
| 9563 | snprintf(buf, sizeof(buf), "%s", spec ? spec : ""); |
| 9564 | char *save = NULL; |
| 9565 | for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) { |
| 9566 | while (*tok == ' ') { |
| 9567 | tok++; |
| 9568 | } |
| 9569 | size_t len = strlen(tok); |
| 9570 | while (len > 0 && tok[len - 1] == ' ') { |
| 9571 | tok[--len] = '\0'; |
| 9572 | } |
| 9573 | if (!tok[0]) { |
| 9574 | continue; |
| 9575 | } |
| 9576 | bool matched = false; |
| 9577 | for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) { |
| 9578 | if (strcmp(tok, CLI_CLIENTS[i].token) == 0) { |
| 9579 | wanted[i] = true; |
| 9580 | matched = true; |
| 9581 | break; |
| 9582 | } |
| 9583 | } |
| 9584 | if (!matched) { |
| 9585 | (void)fprintf(stderr, "error: unknown client: %s\n\n", tok); |
| 9586 | cli_clients_print_list(stderr); |
| 9587 | return false; |
| 9588 | } |
| 9589 | } |
| 9590 | for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) { |
| 9591 | if (!wanted[i]) { |
| 9592 | *(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false; |
| 9593 | } |
| 9594 | } |
| 9595 | return true; |
| 9596 | } |
| 9597 | |
| 9598 | #ifdef CBM_CLI_ENABLE_TEST_API |
| 9599 | bool cbm_cli_clients_apply_selection_for_testing(const char *spec, |
no test coverage detected