Skip to content

Commit

Permalink
Add description elements to config (not available via api, buggy)
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Aug 8, 2023
1 parent cd066bd commit 6232988
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ typedef enum
TYPE_HEX,
TYPE_STRING,
TYPE_FLOAT,
TYPE_TREE_DESC,
TYPE_END
} settings_type;

Expand Down Expand Up @@ -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)
Expand All @@ -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 \
Expand Down
5 changes: 4 additions & 1 deletion src/handler_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -103,18 +116,21 @@ 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)")
OPTION_BOOL("toniebox.slap_enabled", &settings->toniebox.slap_enabled, TRUE, "Enable slapping to skip a track")
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")
Expand Down

0 comments on commit 6232988

Please sign in to comment.