| 7464 | } |
| 7465 | |
| 7466 | static int config_ui_write(const char *key, const char *value) { |
| 7467 | cbm_ui_config_t ui; |
| 7468 | cbm_ui_config_load(&ui); |
| 7469 | if (strcmp(key, CBM_CONFIG_UI_ENABLED) == 0) { |
| 7470 | if (strcmp(value, "true") != 0 && strcmp(value, "false") != 0) { |
| 7471 | (void)fprintf(stderr, "error: %s must be true or false\n", key); |
| 7472 | return CLI_ERR; |
| 7473 | } |
| 7474 | ui.ui_enabled = strcmp(value, "true") == 0; |
| 7475 | } else { |
| 7476 | char *end = NULL; |
| 7477 | long port = strtol(value, &end, 10); |
| 7478 | if (!end || *end || port < 1 || port > 65535) { |
| 7479 | (void)fprintf(stderr, "error: %s must be a port between 1 and 65535\n", key); |
| 7480 | return CLI_ERR; |
| 7481 | } |
| 7482 | ui.ui_port = (int)port; |
| 7483 | } |
| 7484 | if (!cbm_ui_config_save(&ui)) { |
| 7485 | (void)fprintf(stderr, "error: could not write the UI configuration file\n"); |
| 7486 | return CLI_ERR; |
| 7487 | } |
| 7488 | return CLI_OK; |
| 7489 | } |
| 7490 | |
| 7491 | static const config_key_def_t *config_key_lookup(const char *key) { |
| 7492 | for (size_t i = 0; key && i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) { |
no test coverage detected