From 6232988fed9f682b36a479624562690f617f65ef Mon Sep 17 00:00:00 2001 From: SciLor Date: Tue, 8 Aug 2023 07:08:21 +0000 Subject: [PATCH] Add description elements to config (not available via api, buggy) --- include/settings.h | 4 ++++ src/handler_api.c | 5 ++++- src/settings.c | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/settings.h b/include/settings.h index ed2ac092..65d8f03a 100644 --- a/include/settings.h +++ b/include/settings.h @@ -160,6 +160,7 @@ typedef enum TYPE_HEX, TYPE_STRING, TYPE_FLOAT, + TYPE_TREE_DESC, TYPE_END } settings_type; @@ -223,6 +224,7 @@ typedef struct #define OPTION_ADV_UNSIGNED(o, p, d, minVal, maxVal, desc, i, ov) {.option_name = o, .ptr = p, .init = {.unsigned_value = d}, .min = {.unsigned_value = minVal}, .max = {.unsigned_value = maxVal}, .type = TYPE_UNSIGNED, .description = desc, .internal = i, .overlayed = ov}, #define OPTION_ADV_FLOAT(o, p, d, minVal, maxVal, desc, i, ov) {.option_name = o, .ptr = p, .init = {.float_value = d}, .min = {.float_value = minVal}, .max = {.float_value = maxVal}, .type = TYPE_FLOAT, .description = desc, .internal = i, .overlayed = ov}, #define OPTION_ADV_STRING(o, p, d, desc, i, ov) {.option_name = o, .ptr = p, .init = {.string_value = d}, .type = TYPE_STRING, .description = desc, .internal = i, .overlayed = ov}, +#define OPTION_ADV_TREE_DESC(o, p, d, desc, i, ov) {.option_name = o, .ptr = p, .init = {.string_value = d}, .type = TYPE_TREE_DESC, .description = desc, .internal = i, .overlayed = ov}, #define OPTION_BOOL(o, p, d, desc) OPTION_ADV_BOOL(o, p, d, desc, false, false) #define OPTION_SIGNED(o, p, d, min, max, desc) OPTION_ADV_SIGNED(o, p, d, min, max, desc, false, false) @@ -236,6 +238,8 @@ typedef struct #define OPTION_INTERNAL_FLOAT(o, p, d, min, max, desc) OPTION_ADV_FLOAT(o, p, d, min, max, desc, true, false) #define OPTION_INTERNAL_STRING(o, p, d, desc) OPTION_ADV_STRING(o, p, d, desc, true, false) +#define OPTION_TREE_DESC(o, desc) OPTION_ADV_TREE_DESC(o, NULL, NULL, desc, false, false) + #define OPTION_END() \ { \ .type = TYPE_END \ diff --git a/src/handler_api.c b/src/handler_api.c index db8bc84e..2a909b7d 100644 --- a/src/handler_api.c +++ b/src/handler_api.c @@ -113,7 +113,7 @@ error_t handleApiGetIndex(HttpConnection *connection, const char_t *uri, const c { break; } - if (opt->internal) + if (opt->internal || opt->type == TYPE_TREE_DESC) { pos++; continue; @@ -150,6 +150,9 @@ error_t handleApiGetIndex(HttpConnection *connection, const char_t *uri, const c cJSON_AddStringToObject(jsonEntry, "type", "float"); cJSON_AddNumberToObject(jsonEntry, "value", settings_get_float_ovl(opt->option_name, overlay)); break; + case TYPE_TREE_DESC: + cJSON_AddStringToObject(jsonEntry, "type", "desc"); + break; default: break; } diff --git a/src/settings.c b/src/settings.c index e179b9b5..b7b6fce1 100644 --- a/src/settings.c +++ b/src/settings.c @@ -25,12 +25,17 @@ static void option_map_init(uint8_t settingsId) OPTION_INTERNAL_UNSIGNED("configVersion", &settings->configVersion, 0, 0, 255, "Config version") OPTION_INTERNAL_STRING("commonName", &settings->commonName, "", "common name of the certificate (for overlays)") + + OPTION_TREE_DESC("log", "Logging") OPTION_UNSIGNED("log.level", &settings->log.level, 4, 0, 6, "0=off - 6=verbose") OPTION_BOOL("log.color", &settings->log.color, TRUE, "Colored log") /* settings for HTTPS server */ + OPTION_TREE_DESC("core.server", "Server ports") OPTION_UNSIGNED("core.server.https_port", &settings->core.http_port, 443, 1, 65535, "HTTPS port") OPTION_UNSIGNED("core.server.http_port", &settings->core.https_port, 80, 1, 65535, "HTTP port") + + OPTION_TREE_DESC("core.server", "HTTP server") OPTION_STRING("core.host_url", &settings->core.host_url, "http://localhost/", "URL to teddyCloud server") OPTION_STRING("core.certdir", &settings->core.certdir, "certs/client", "Directory where to upload genuine client certs to") OPTION_STRING("core.contentdir", &settings->core.contentdir, "default", "Directory where cloud content is placed") @@ -39,17 +44,23 @@ static void option_map_init(uint8_t settingsId) OPTION_STRING("core.wwwdir", &settings->core.wwwdir, "www", "Directory where web content is placed") OPTION_STRING("core.sslkeylogfile", &settings->core.sslkeylogfile, "", "SSL/TLS key log filename") + OPTION_TREE_DESC("core.server_cert", "HTTPS server certificates") + OPTION_TREE_DESC("core.client_cert.file", "File certificates") OPTION_STRING("core.server_cert.file.ca", &settings->core.server_cert.file.ca, "certs/server/ca-root.pem", "Server CA") OPTION_STRING("core.server_cert.file.crt", &settings->core.server_cert.file.crt, "certs/server/teddy-cert.pem", "Server certificate") OPTION_STRING("core.server_cert.file.key", &settings->core.server_cert.file.key, "certs/server/teddy-key.pem", "Server key") + OPTION_TREE_DESC("core.server_cert.data", "Raw certificates") OPTION_STRING("core.server_cert.data.ca", &settings->core.server_cert.data.ca, "", "Server CA data") OPTION_STRING("core.server_cert.data.crt", &settings->core.server_cert.data.crt, "", "Server certificate data") OPTION_STRING("core.server_cert.data.key", &settings->core.server_cert.data.key, "", "Server key data") /* settings for HTTPS/cloud client */ + OPTION_TREE_DESC("core.client_cert", "Cloud client certificates") + OPTION_TREE_DESC("core.client_cert.file", "File certificates") OPTION_STRING("core.client_cert.file.ca", &settings->core.client_cert.file.ca, "certs/client/ca.der", "Client CA") OPTION_STRING("core.client_cert.file.crt", &settings->core.client_cert.file.crt, "certs/client/client.der", "Client certificate") OPTION_STRING("core.client_cert.file.key", &settings->core.client_cert.file.key, "certs/client/private.der", "Client key") + OPTION_TREE_DESC("core.client_cert.data", "Raw certificates") OPTION_STRING("core.client_cert.data.ca", &settings->core.client_cert.data.ca, "", "Client CA") OPTION_STRING("core.client_cert.data.crt", &settings->core.client_cert.data.crt, "", "Client certificate data") OPTION_STRING("core.client_cert.data.key", &settings->core.client_cert.data.key, "", "Client key data") @@ -59,6 +70,7 @@ static void option_map_init(uint8_t settingsId) OPTION_BOOL("core.flex_enabled", &settings->core.flex_enabled, TRUE, "When enabled this UID always gets assigned the audio assigned from web interface") OPTION_STRING("core.flex_uid", &settings->core.flex_uid, "", "UID which shall get selected audio files assigned") + OPTION_TREE_DESC("internal", "Internal") OPTION_INTERNAL_STRING("internal.server.ca", &settings->internal.server.ca, "", "Server CA data") OPTION_INTERNAL_STRING("internal.server.crt", &settings->internal.server.crt, "", "Server certificate data") OPTION_INTERNAL_STRING("internal.server.key", &settings->internal.server.key, "", "Server key data") @@ -88,6 +100,7 @@ static void option_map_init(uint8_t settingsId) OPTION_INTERNAL_STRING("internal.version.v_long", &settings->internal.version.v_long, "", "Long version string") OPTION_INTERNAL_STRING("internal.version.v_full", &settings->internal.version.v_full, "", "Full version string") + OPTION_TREE_DESC("cloud", "Cloud") OPTION_BOOL("cloud.enabled", &settings->cloud.enabled, FALSE, "Generally enable cloud operation") OPTION_STRING("cloud.remote_hostname", &settings->cloud.remote_hostname, "prod.de.tbs.toys", "Hostname of remote cloud server") OPTION_UNSIGNED("cloud.remote_port", &settings->cloud.remote_port, 443, 1, 65535, "Port of remote cloud server") @@ -103,6 +116,7 @@ static void option_map_init(uint8_t settingsId) OPTION_BOOL("cloud.markCustomTagByUid", &settings->cloud.markCustomTagByUid, TRUE, "Automatically mark custom tags by Uid") OPTION_BOOL("cloud.prioCustomContent", &settings->cloud.prioCustomContent, TRUE, "Priotize custom over boxine content (force update)") + OPTION_TREE_DESC("toniebox", "Toniebox") OPTION_BOOL("toniebox.overrideCloud", &settings->toniebox.overrideCloud, TRUE, "Override toniebox settings from the boxine cloud") OPTION_UNSIGNED("toniebox.max_vol_spk", &settings->toniebox.max_vol_spk, 3, 0, 3, "Limit speaker volume (0-3)") OPTION_UNSIGNED("toniebox.max_vol_hdp", &settings->toniebox.max_vol_hdp, 3, 0, 3, "Limit headphone volume (0-3)") @@ -110,11 +124,13 @@ static void option_map_init(uint8_t settingsId) OPTION_BOOL("toniebox.slap_back_left", &settings->toniebox.slap_back_left, FALSE, "False=left-backwards - True=left-forward") OPTION_UNSIGNED("toniebox.led", &settings->toniebox.led, 0, 0, 2, "0=on, 1=off, 2=dimmed") + OPTION_TREE_DESC("rtnl", "RTNL log") OPTION_BOOL("rtnl.logRaw", &settings->rtnl.logRaw, FALSE, "Enable raw rtnl logging") OPTION_BOOL("rtnl.logHuman", &settings->rtnl.logHuman, FALSE, "Enable human readable rtnl logging") OPTION_STRING("rtnl.logRawFile", &settings->rtnl.logRawFile, "config/rtnl.bin", "RTNL raw logfile") OPTION_STRING("rtnl.logHumanFile", &settings->rtnl.logHumanFile, "config/rtnl.csv", "RTNL human readable logfile") + OPTION_TREE_DESC("mqtt", "MQTT") OPTION_BOOL("mqtt.enabled", &settings->mqtt.enabled, FALSE, "Enable MQTT service") OPTION_STRING("mqtt.hostname", &settings->mqtt.hostname, "", "MQTT hostname") OPTION_UNSIGNED("mqtt.port", &settings->mqtt.port, 1833, 1, 65535, "Port of MQTT server")