admin: Global settings can be specified on the command-line. Removed some previous, less thorough ways of configuring things. #102
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
This commit is contained in:
@ -314,13 +314,6 @@ static JSValue _util_parseHttpResponse(JSContext* context, JSValueConst this_val
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef enum _value_kind_t
|
||||
{
|
||||
k_kind_bool,
|
||||
k_kind_int,
|
||||
k_kind_string,
|
||||
} value_kind_t;
|
||||
|
||||
static const char* k_kind_name[] = {
|
||||
[k_kind_bool] = "bool",
|
||||
[k_kind_int] = "int",
|
||||
@ -329,7 +322,7 @@ static const char* k_kind_name[] = {
|
||||
|
||||
typedef struct _setting_value_t
|
||||
{
|
||||
value_kind_t kind;
|
||||
tf_setting_kind_t kind;
|
||||
union
|
||||
{
|
||||
bool bool_value;
|
||||
@ -348,6 +341,13 @@ typedef struct _setting_t
|
||||
|
||||
static const setting_t k_settings[] = {
|
||||
{ .name = "code_of_conduct", .type = "textarea", .description = "Code of conduct presented at sign-in.", .default_value = { .kind = k_kind_string, .string_value = NULL } },
|
||||
{ .name = "ssb_port",
|
||||
.type = "integer",
|
||||
.description = "Port on which to listen for SSB secure handshake connections.",
|
||||
.default_value = { .kind = k_kind_int, .int_value = 8008 } },
|
||||
{ .name = "http_port", .type = "integer", .description = "Port on which to listen for HTTP connections.", .default_value = { .kind = k_kind_int, .int_value = 12345 } },
|
||||
{ .name = "https_port", .type = "integer", .description = "Port on which to listen for secure HTTP connections.", .default_value = { .kind = k_kind_int, .int_value = 0 } },
|
||||
{ .name = "out_http_port_file", .type = "hidden", .description = "File to which to write bound HTTP port.", .default_value = { .kind = k_kind_string, .string_value = NULL } },
|
||||
{ .name = "blob_fetch_age_seconds",
|
||||
.type = "integer",
|
||||
.description = "Only blobs mentioned more recently than this age will be automatically fetched.",
|
||||
@ -393,21 +393,31 @@ static const setting_t k_settings[] = {
|
||||
.type = "boolean",
|
||||
.description = "Whether connections are accepted from accounts that aren't in the replication range or otherwise already known.",
|
||||
.default_value = { .kind = k_kind_bool, .bool_value = true } },
|
||||
{ .name = "autologin", .type = "boolean", .description = "Whether mobile autologin is supported.", .default_value = { .kind = k_kind_bool, .bool_value = TF_IS_MOBILE != 0 } },
|
||||
};
|
||||
|
||||
static const setting_t* _util_get_setting(const char* name, value_kind_t kind)
|
||||
static const setting_t* _util_get_setting(const char* name, tf_setting_kind_t kind)
|
||||
{
|
||||
for (int i = 0; i < tf_countof(k_settings); i++)
|
||||
{
|
||||
if (strcmp(k_settings[i].name, name) == 0 && k_settings[i].default_value.kind == kind)
|
||||
if (strcmp(k_settings[i].name, name) == 0 && (kind == k_kind_unknown || k_settings[i].default_value.kind == kind))
|
||||
{
|
||||
return &k_settings[i];
|
||||
}
|
||||
}
|
||||
tf_printf("Did not find global setting of type %s: %s.\n", k_kind_name[kind], name);
|
||||
if (kind != k_kind_unknown)
|
||||
{
|
||||
tf_printf("Did not find global setting of type %s: %s.\n", k_kind_name[kind], name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tf_setting_kind_t tf_util_get_global_setting_kind(const char* name)
|
||||
{
|
||||
const setting_t* setting = _util_get_setting(name, k_kind_unknown);
|
||||
return setting ? setting->default_value.kind : k_kind_unknown;
|
||||
}
|
||||
|
||||
bool tf_util_get_default_global_setting_bool(const char* name)
|
||||
{
|
||||
const setting_t* setting = _util_get_setting(name, k_kind_bool);
|
||||
@ -446,12 +456,41 @@ static JSValue _util_defaultGlobalSettings(JSContext* context, JSValueConst this
|
||||
JS_SetPropertyStr(
|
||||
context, entry, "default_value", k_settings[i].default_value.string_value ? JS_NewString(context, k_settings[i].default_value.string_value) : JS_UNDEFINED);
|
||||
break;
|
||||
case k_kind_unknown:
|
||||
break;
|
||||
}
|
||||
JS_SetPropertyStr(context, settings, k_settings[i].name, entry);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
void tf_util_document_settings(const char* line_prefix)
|
||||
{
|
||||
char buffer[32];
|
||||
for (int i = 0; i < tf_countof(k_settings); i++)
|
||||
{
|
||||
const char* default_value = NULL;
|
||||
const char* quote = "";
|
||||
switch (k_settings[i].default_value.kind)
|
||||
{
|
||||
case k_kind_bool:
|
||||
default_value = k_settings[i].default_value.bool_value ? "true" : "false";
|
||||
break;
|
||||
case k_kind_string:
|
||||
quote = "\"";
|
||||
default_value = k_settings[i].default_value.string_value ? k_settings[i].default_value.string_value : "";
|
||||
break;
|
||||
case k_kind_int:
|
||||
snprintf(buffer, sizeof(buffer), "%d", k_settings[i].default_value.int_value);
|
||||
default_value = buffer;
|
||||
break;
|
||||
case k_kind_unknown:
|
||||
break;
|
||||
}
|
||||
tf_printf("%s%s (default: %s%s%s): %s\n", line_prefix, k_settings[i].name, quote, default_value, quote, k_settings[i].description);
|
||||
}
|
||||
}
|
||||
|
||||
JSValue tf_util_new_uint8_array(JSContext* context, const uint8_t* data, size_t size)
|
||||
{
|
||||
JSValue array_buffer = JS_NewArrayBufferCopy(context, data, size);
|
||||
|
Reference in New Issue
Block a user