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". */
| 10774 | * printing the vocabulary) when a token is unknown, so a typo can never be |
| 10775 | * mistaken for "that client was not installed". */ |
| 10776 | static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) { |
| 10777 | bool wanted[CLI_CLIENT_COUNT]; |
| 10778 | memset(wanted, 0, sizeof(wanted)); |
| 10779 | char buf[CLI_BUF_1K]; |
| 10780 | snprintf(buf, sizeof(buf), "%s", spec ? spec : ""); |
| 10781 | char *save = NULL; |
| 10782 | for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) { |
| 10783 | while (*tok == ' ') { |
| 10784 | tok++; |
| 10785 | } |
| 10786 | size_t len = strlen(tok); |
| 10787 | while (len > 0 && tok[len - 1] == ' ') { |
| 10788 | tok[--len] = '\0'; |
| 10789 | } |
| 10790 | if (!tok[0]) { |
| 10791 | continue; |
| 10792 | } |
| 10793 | bool matched = false; |
| 10794 | for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) { |
| 10795 | if (strcmp(tok, CLI_CLIENTS[i].token) == 0) { |
| 10796 | wanted[i] = true; |
| 10797 | matched = true; |
| 10798 | break; |
| 10799 | } |
| 10800 | } |
| 10801 | if (!matched) { |
| 10802 | matched = cbm_agent_client_by_stable_id(tok) != NULL; |
| 10803 | } |
| 10804 | if (!matched) { |
| 10805 | (void)fprintf(stderr, "error: unknown client: %s\n\n", tok); |
| 10806 | cli_clients_print_list(stderr); |
| 10807 | return false; |
| 10808 | } |
| 10809 | } |
| 10810 | for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) { |
| 10811 | if (!wanted[i]) { |
| 10812 | *(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false; |
| 10813 | } |
| 10814 | } |
| 10815 | return true; |
| 10816 | } |
| 10817 | |
| 10818 | #ifdef CBM_CLI_ENABLE_TEST_API |
| 10819 | bool cbm_cli_clients_apply_selection_for_testing(const char *spec, |
no test coverage detected