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". */
| 10555 | * printing the vocabulary) when a token is unknown, so a typo can never be |
| 10556 | * mistaken for "that client was not installed". */ |
| 10557 | static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) { |
| 10558 | bool wanted[CLI_CLIENT_COUNT]; |
| 10559 | memset(wanted, 0, sizeof(wanted)); |
| 10560 | char buf[CLI_BUF_1K]; |
| 10561 | snprintf(buf, sizeof(buf), "%s", spec ? spec : ""); |
| 10562 | char *save = NULL; |
| 10563 | for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) { |
| 10564 | while (*tok == ' ') { |
| 10565 | tok++; |
| 10566 | } |
| 10567 | size_t len = strlen(tok); |
| 10568 | while (len > 0 && tok[len - 1] == ' ') { |
| 10569 | tok[--len] = '\0'; |
| 10570 | } |
| 10571 | if (!tok[0]) { |
| 10572 | continue; |
| 10573 | } |
| 10574 | bool matched = false; |
| 10575 | for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) { |
| 10576 | if (strcmp(tok, CLI_CLIENTS[i].token) == 0) { |
| 10577 | wanted[i] = true; |
| 10578 | matched = true; |
| 10579 | break; |
| 10580 | } |
| 10581 | } |
| 10582 | if (!matched) { |
| 10583 | matched = cbm_agent_client_by_stable_id(tok) != NULL; |
| 10584 | } |
| 10585 | if (!matched) { |
| 10586 | (void)fprintf(stderr, "error: unknown client: %s\n\n", tok); |
| 10587 | cli_clients_print_list(stderr); |
| 10588 | return false; |
| 10589 | } |
| 10590 | } |
| 10591 | for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) { |
| 10592 | if (!wanted[i]) { |
| 10593 | *(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false; |
| 10594 | } |
| 10595 | } |
| 10596 | return true; |
| 10597 | } |
| 10598 | |
| 10599 | #ifdef CBM_CLI_ENABLE_TEST_API |
| 10600 | bool cbm_cli_clients_apply_selection_for_testing(const char *spec, |
no test coverage detected