| 6649 | } |
| 6650 | |
| 6651 | static int config_ui_write(const char *key, const char *value) { |
| 6652 | cbm_ui_config_t ui; |
| 6653 | cbm_ui_config_load(&ui); |
| 6654 | if (strcmp(key, CBM_CONFIG_UI_ENABLED) == 0) { |
| 6655 | if (strcmp(value, "true") != 0 && strcmp(value, "false") != 0) { |
| 6656 | (void)fprintf(stderr, "error: %s must be true or false\n", key); |
| 6657 | return CLI_ERR; |
| 6658 | } |
| 6659 | ui.ui_enabled = strcmp(value, "true") == 0; |
| 6660 | } else { |
| 6661 | char *end = NULL; |
| 6662 | long port = strtol(value, &end, 10); |
| 6663 | if (!end || *end || port < 1 || port > 65535) { |
| 6664 | (void)fprintf(stderr, "error: %s must be a port between 1 and 65535\n", key); |
| 6665 | return CLI_ERR; |
| 6666 | } |
| 6667 | ui.ui_port = (int)port; |
| 6668 | } |
| 6669 | if (!cbm_ui_config_save(&ui)) { |
| 6670 | (void)fprintf(stderr, "error: could not write the UI configuration file\n"); |
| 6671 | return CLI_ERR; |
| 6672 | } |
| 6673 | return CLI_OK; |
| 6674 | } |
| 6675 | |
| 6676 | static const config_key_def_t *config_key_lookup(const char *key) { |
| 6677 | for (size_t i = 0; key && i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) { |
no test coverage detected