From 0ce72b52e9517f106fbaf63113c7460ff50f1080 Mon Sep 17 00:00:00 2001 From: LDA Date: Thu, 5 Sep 2024 10:05:25 +0200 Subject: [PATCH] [DEL] Remove wizard --- Makefile | 4 +- src/Main.c | 4 + src/Parsee/Config.c | 195 +------------------------------------------- 3 files changed, 8 insertions(+), 195 deletions(-) diff --git a/Makefile b/Makefile index 82e34f4..806f082 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ PREFIX ?=/usr/local AYAS=ayaya ETC=etc -CFLAGS=-I$(SOURCE) -I$(INCLUDES) -I$(CYTO_INC) -DNAME="\"$(NAME)\"" -DVERSION="\"$(VERSION)\"" -DREPOSITORY=\"$(REPOSITORY)\" -DCODE=\"$(CODE)\" -O3 -g -Wall -Werror -LDFLAGS=-L $(CYTO_LIB) -lCytoplasm -O3 -g +CFLAGS=-I$(SOURCE) -I$(INCLUDES) -I$(CYTO_INC) -DNAME="\"$(NAME)\"" -DVERSION="\"$(VERSION)\"" -DREPOSITORY=\"$(REPOSITORY)\" -DCODE=\"$(CODE)\" -O2 -g -Wall -Werror +LDFLAGS=-L $(CYTO_LIB) -lCytoplasm -O2 -g AFLAGS=-C "$(ETC)/ayadoc/style.css" -p "$(NAME)" # ============================ Compilation ================================= SRC_FILES:=$(shell find $(SOURCE) -name '*.c') $(shell find $(ETC)/media -name '*.png') diff --git a/src/Main.c b/src/Main.c index 760ca03..ff6f72b 100644 --- a/src/Main.c +++ b/src/Main.c @@ -155,6 +155,10 @@ Main(Array *args, HashMap *env) ParseeConfigLoad(configuration); ParseeConfigInit(); parsee_conf = ParseeConfigGet(); + if (!parsee_conf) + { + goto end; + } Log(LOG_NOTICE, "Connecting to XMPP..."); diff --git a/src/Parsee/Config.c b/src/Parsee/Config.c index f1a14b6..72eff53 100644 --- a/src/Parsee/Config.c +++ b/src/Parsee/Config.c @@ -11,206 +11,15 @@ static ParseeConfig *config = NULL; -static char * -GetLine(void) -{ - Stream *input = StreamStdin(); - char *out = NULL; - size_t length; - UtilGetLine(&out, &length, input); - - if (out) - { - char *line = strchr(out, '\n'); - if (line) - { - *line = '\0'; - } - } - - return out; -} - -#include -static char * -PromptString(const char *expression, const char *def, ...) -{ - Stream *output = StreamStdout(); - char *out = NULL; - va_list ap; - - while (!out) - { - va_start(ap, def); - - StreamVprintf(output, expression, ap); - if (def) - { - StreamPrintf(output, " [%s]", def); - } - StreamPrintf(output, ": "); - StreamFlush(output); - - va_end(ap); - - out = GetLine(); - if (!*out) - { - Free(out); - out = NULL; - if (def) - { - return StrDuplicate(def); - } - } - Log(LOG_INFO, "R=%s", out); - } - - return out; -} -static int -PromptInteger(const char *expression, int def, ...) -{ - Stream *output = StreamStdout(); - char *out; - long l; - va_list ap; - - va_start(ap, def); - - StreamVprintf(output, expression, ap); - if (def >= 0) - { - StreamPrintf(output, " [%d]", def); - } - StreamPrintf(output, ": "); - StreamFlush(output); - - va_end(ap); - while (true) - { - char *inval; - out = GetLine(); - l = strtol(out, &inval, 10); - Free(out); - - /* Not a use-after-free, as we reference only the addresses. */ - if (l != 0 || inval != out) - { - break; - } - - if (def >= 0) - { - return def; - } - } - - return l; -} - void ParseeConfigInit(void) { - Stream *stream; - HashMap *json; if (config) { return; } - - /* TODO: Get rid of this, as parsee-config is the main way of doing it */ - Log(LOG_NOTICE, "It seems like it is the first time you have configured "); - Log(LOG_NOTICE, "Parsee."); - Log(LOG_NOTICE, "As such, I need to ask you a couple of questions before "); - Log(LOG_NOTICE, "being able to use it."); - Log(LOG_NOTICE, "(don't worry; it won't take too long.)"); - Log(LOG_NOTICE, ""); - Log(LOG_NOTICE, ""); - - config = Malloc(sizeof(*config)); - config->as_token = StrRandom(32); - config->hs_token = StrRandom(32); - config->http_threads = 8; - config->xmpp_threads = 8; - config->db_size = 64 MB; - - config->sender_localpart = PromptString( - "Name of the bridge bot, used for commands and bridged rooms", - "_parsee_bridge" - ); - config->namespace_base = PromptString( - "Base namespace for Parsee (so foo@bar.com => @[NS]_foo=40bar.com)", - "_jabber" - ); - - config->listen_as = StrDuplicate("localhost"); - config->port = PromptInteger( - "Matrix port for the AS service to use", - 7642 - ); - - - config->component_host = PromptString( - "XMPP component to be used for the configuration", - NULL - ); - config->component_port = PromptInteger( - "XMPP port for to use for '%s'", - 5347, config->component_host - ); - config->shared_comp_secret = PromptString( - "%s's shared secret", - NULL, config->component_host - ); - - config->homeserver_host = PromptString( - "Delegated homeserver to be used for the configuration", - NULL - ); - config->homeserver_port = PromptInteger( - "HTTP port for to use for '%s'", - 443, config->homeserver_host - ); - - config->db_path = PromptString( - "Base directory for Parsee data", - NULL - ); - config->media_base = PromptString( - "Base media URL for bridged media", - NULL - ); - - config->server_base = StrDuplicate(config->homeserver_host); - - Log(LOG_NOTICE, "Done! Please look over to the parsee.yaml file, "); - Log(LOG_NOTICE, "and follow the instructions listed in it. Then, "); - Log(LOG_NOTICE, "restart Parsee. "); - Log(LOG_NOTICE, "------------------------------------------------"); - - stream = StreamOpen("parsee.json", "w"); - json = HashMapCreate(); - HashMapSet(json, "as_token", JsonValueString(config->as_token)); - HashMapSet(json, "hs_token", JsonValueString(config->hs_token)); - - HashMapSet(json, "sender", JsonValueString(config->sender_localpart)); - HashMapSet(json, "namespace", JsonValueString(config->namespace_base)); - HashMapSet(json, "listen_as", JsonValueString(config->listen_as)); - HashMapSet(json, "port", JsonValueInteger(config->port)); - - HashMapSet(json, "hs_base", JsonValueString(config->server_base)); - HashMapSet(json, "hs_host", JsonValueString(config->homeserver_host)); - HashMapSet(json, "hs_port", JsonValueInteger(config->homeserver_port)); - - HashMapSet(json, "component_host", JsonValueString(config->component_host)); - HashMapSet(json, "component_port", JsonValueInteger(config->component_port)); - HashMapSet(json, "shared_comp_secret", JsonValueString(config->shared_comp_secret)); - HashMapSet(json, "db", JsonValueString(config->db_path)); - - JsonEncode(json, stream, JSON_PRETTY); - JsonFree(json); - StreamClose(stream); + Log(LOG_ERR, "No config file found."); + Log(LOG_ERR, "Please use parsee-config to initialise %s.", NAME); } void ParseeConfigLoad(char *conf)