diff --git a/DATES.TXT b/DATES.TXT index 51c7719..8e32ab3 100644 --- a/DATES.TXT +++ b/DATES.TXT @@ -1,6 +1,6 @@ Some dates for Parsee-related events. They mostly serve as LDA's TODOs with a strict deadline: - - ~September 2024: + - ~September 2024[star-of-hope]: Get Parsee into the _Phantasmagoria of Bug View_ stage (essentially v0.0.1 for a public testing) once I can afford `yama`, and start bridging the Matrix room alongside a shiny XMPP MUC, bridged by diff --git a/src/Main.c b/src/Main.c index a345778..b8e148b 100644 --- a/src/Main.c +++ b/src/Main.c @@ -3,12 +3,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -30,7 +32,7 @@ ParseeUptime(void) } int -Main(void) +Main(Array *args, HashMap *env) { HttpServerConfig conf; const ParseeConfig *parsee_conf; @@ -50,13 +52,34 @@ Main(void) ParseeConfigLoad("parsee.json"); ParseeConfigInit(); - + parsee_conf = ParseeConfigGet(); + + { + ArgParseState state; + int flag; + int xmpp = 8; + int http = 8; + + ArgParseStateInit(&state); + while ((flag = ArgParse(&state, args, "H:J:")) != -1) + { + switch (flag) + { + case 'H': + http = strtol(state.optArg, NULL, 10); + break; + case 'J': + xmpp = strtol(state.optArg, NULL, 10); + break; + } + } + ParseeSetThreads(xmpp, http); + } /* Write out the config file to a YAML document */ yaml = StreamOpen("parsee.yaml", "w"); ParseeExportConfigYAML(yaml); StreamClose(yaml); - parsee_conf = ParseeConfigGet(); { Log(LOG_NOTICE, "Connecting to XMPP..."); jabber = XMPPInitialiseCompStream( @@ -83,8 +106,8 @@ Main(void) ASRegisterUser(parsee_conf, parsee_conf->sender_localpart); conf.port = parsee_conf->port; - conf.threads = 4; - conf.maxConnections = 32; + conf.threads = parsee_conf->http_threads; + conf.maxConnections = 32; /* TODO */ conf.handlerArgs = ParseeInitData(jabber); conf.handler = ParseeRequest; diff --git a/src/Parsee/Config.c b/src/Parsee/Config.c index a103014..413b431 100644 --- a/src/Parsee/Config.c +++ b/src/Parsee/Config.c @@ -133,6 +133,8 @@ ParseeConfigInit(void) config = Malloc(sizeof(*config)); config->as_token = StrRandom(32); config->hs_token = StrRandom(32); + config->http_threads = 8; + config->xmpp_threads = 8; /* TODO: This is NOT user friendly, and I know it! */ config->sender_localpart = PromptString( @@ -236,6 +238,9 @@ ParseeConfigLoad(char *conf) #define CopyToInt(to, str) config->to = (int) ( \ JsonValueAsInteger(HashMapGet(json, str)) \ ) + + config->http_threads = 8; + config->xmpp_threads = 8; CopyToStr(as_token, "as_token"); CopyToStr(hs_token, "hs_token"); @@ -260,6 +265,17 @@ ParseeConfigLoad(char *conf) StreamClose(stream); } +void +ParseeSetThreads(int xmpp, int http) +{ + if (!config) + { + return; + } + config->http_threads = http; + config->xmpp_threads = xmpp; +} + void ParseeExportConfigYAML(Stream *stream) { diff --git a/src/XMPPThread/ReListener.c b/src/XMPPThread/ReListener.c index 76d9e5a..85bcc44 100644 --- a/src/XMPPThread/ReListener.c +++ b/src/XMPPThread/ReListener.c @@ -155,7 +155,7 @@ ParseeXMPPThread(void *argp) /* ... and its readers. */ /* TODO: Make that configurable. */ - info.available_dispatchers = 16; + info.available_dispatchers = args->config->xmpp_threads; info.dispatchers = Malloc( sizeof(*info.dispatchers) * info.available_dispatchers ); diff --git a/src/include/Parsee.h b/src/include/Parsee.h index e8b068e..1b6cb84 100644 --- a/src/include/Parsee.h +++ b/src/include/Parsee.h @@ -41,6 +41,9 @@ typedef struct ParseeConfig { /* ------- DB -------- */ char *db_path; + + /* - COMMAND-LINE FLAGS - */ + int xmpp_threads, http_threads; } ParseeConfig; typedef struct ParseeData { @@ -234,7 +237,7 @@ extern void ParseePushHeadTable(char *room, char *id); extern char *ParseeLookupHead(char *room); extern void ParseeDestroyHeadTable(void); -/* Disables a user/room/MUC's ability to interact from Parsee, and attempts +/** Disables a user/room/MUC's ability to interact from Parsee, and attempts * to ban them from rooms where Parsee has the ability to do so ("noflying"). * --------------- * Returns: NOTHING @@ -242,7 +245,7 @@ extern void ParseeDestroyHeadTable(void); * Modifies: the database */ extern void ParseeGlobalBan(ParseeData *, char *user, char *reason); -/* Verifies if a user was banned globally. If so (and if {room} is set), +/** Verifies if a user was banned globally. If so (and if {room} is set), * tries to ban the user from it. * --------------- * Returns: NOTHING @@ -260,7 +263,7 @@ extern bool ParseeVerifyDMStanza(ParseeData *data, char *room_id, char *id); * Modifies: NOTHING */ extern bool ParseeIsAdmin(ParseeData *data, char *user); -/* Measures Parsee's overall uptime. +/** Measures Parsee's overall uptime. * ---------------- * Returns: uptime since the call to Main in milliseconds. * Modifies: NOTHING */ @@ -301,4 +304,10 @@ extern void ParseeAchievement(const char *func, const char *msg, bool die); * Thrasher: Free */ extern char * ParseeGenerateMTO(char *common_id); +/** Sets the amount of XMPP/HTTP threads to use + * ---------------------- + * Returns: NOTHING + * Modifies: the Parsee config */ +extern void ParseeSetThreads(int xmpp, int http); + #endif