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

This commit is contained in:
2025-02-16 13:37:25 -05:00
parent 6247529799
commit c794c1b885
14 changed files with 201 additions and 173 deletions

View File

@ -9,6 +9,7 @@
#include "packetstream.h"
#include "serialize.h"
#include "socket.js.h"
#include "ssb.db.h"
#include "ssb.h"
#include "ssb.js.h"
#include "taskstub.js.h"
@ -154,9 +155,6 @@ typedef struct _tf_task_t
JSValue _loadedFiles;
const char* _network_key;
int _ssb_port;
int _http_port;
int _https_port;
char _db_path[256];
char _zip_path[256];
char _root_path[256];
@ -398,6 +396,7 @@ static JSValue _tf_task_exit(JSContext* context, JSValueConst this_val, int argc
int exitCode = 0;
JS_ToInt32(task->_context, &exitCode, argv[0]);
tf_trace_end(task->_trace);
tf_printf("EXIT %d\n", exitCode);
exit(exitCode);
return JS_UNDEFINED;
}
@ -1680,38 +1679,6 @@ void tf_task_activate(tf_task_t* task)
JS_DefinePropertyGetSet(context, global, atom, JS_NewCFunction(context, _tf_task_get_parent, "parent", 0), JS_UNDEFINED, 0);
JS_FreeAtom(context, atom);
JSValue tildefriends = JS_NewObject(context);
JSValue args = JS_NewObject(context);
JS_SetPropertyStr(context, tildefriends, "args", args);
if (task->_args)
{
char* saveptr = NULL;
char* copy = tf_strdup(task->_args);
char* start = copy;
while (true)
{
char* assignment = strtok_r(start, ",", &saveptr);
start = NULL;
if (!assignment)
{
break;
}
char* equals = strchr(assignment, '=');
if (equals)
{
*equals = '\0';
JS_SetPropertyStr(context, args, assignment, JS_NewString(context, equals + 1));
}
else
{
tf_printf("Assignment missing '=': %s.\n", assignment);
exit(1);
}
}
tf_free(copy);
}
JS_SetPropertyStr(context, global, "tildefriends", tildefriends);
task->_trace = tf_trace_create();
if (task->_trusted)
{
@ -1732,23 +1699,45 @@ void tf_task_activate(tf_task_t* task)
tf_ssb_register(context, task->_ssb);
tf_ssb_set_hitch_callback(task->_ssb, _tf_task_record_hitch, task);
int actual_ssb_port = task->_ssb_port;
if (task->_args)
{
sqlite3* db = tf_ssb_acquire_db_writer(task->_ssb);
char* saveptr = NULL;
char* copy = tf_strdup(task->_args);
char* start = copy;
while (true)
{
char* assignment = strtok_r(start, ",", &saveptr);
start = NULL;
if (!assignment)
{
break;
}
char* equals = strchr(assignment, '=');
if (equals)
{
*equals = '\0';
tf_ssb_db_set_global_setting_from_string(db, assignment, equals + 1);
}
else
{
tf_printf("Assignment missing '=': %s.\n", assignment);
exit(1);
}
}
tf_free(copy);
tf_ssb_release_db_writer(task->_ssb, db);
}
if (task->_ssb_port)
int64_t ssb_port = 0;
sqlite3* db = tf_ssb_acquire_db_reader(task->_ssb);
tf_ssb_db_get_global_setting_int64(db, "ssb_port", &ssb_port);
tf_ssb_release_db_reader(task->_ssb, db);
if (ssb_port)
{
tf_ssb_broadcast_listener_start(task->_ssb, false);
tf_ssb_broadcast_sender_start(task->_ssb);
actual_ssb_port = tf_ssb_server_open(task->_ssb, task->_ssb_port);
}
JS_SetPropertyStr(context, tildefriends, "ssb_port", JS_NewInt32(context, actual_ssb_port));
if (task->_http_port)
{
JS_SetPropertyStr(context, tildefriends, "http_port", JS_NewInt32(context, task->_http_port));
}
if (task->_https_port)
{
JS_SetPropertyStr(context, tildefriends, "https_port", JS_NewInt32(context, task->_https_port));
tf_ssb_server_open(task->_ssb, ssb_port);
}
JS_SetPropertyStr(context, global, "getStats", JS_NewCFunction(context, _tf_task_getStats, "getStats", 0));
@ -1999,21 +1988,6 @@ void tf_task_set_ssb_network_key(tf_task_t* task, const char* network_key)
task->_network_key = network_key;
}
void tf_task_set_ssb_port(tf_task_t* task, int port)
{
task->_ssb_port = port;
}
void tf_task_set_http_port(tf_task_t* task, int port)
{
task->_http_port = port;
}
void tf_task_set_https_port(tf_task_t* task, int port)
{
task->_https_port = port;
}
void tf_task_set_db_path(tf_task_t* task, const char* db_path)
{
snprintf(task->_db_path, sizeof(task->_db_path), "%s", db_path);