From 46b5a66bb09f9c45cca210c68acfeb69da7cccff Mon Sep 17 00:00:00 2001 From: lemon-sh Date: Thu, 16 Dec 2021 22:16:13 +0100 Subject: [PATCH] Prepare for cleanup --- src/ansicolor.h | 38 +++++++++++++++++++------------------- src/connlist.c | 2 +- src/connlist.h | 1 - src/main.c | 24 ++++++++++++------------ src/utils.h | 2 ++ 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/ansicolor.h b/src/ansicolor.h index f9b4f16..59e174c 100644 --- a/src/ansicolor.h +++ b/src/ansicolor.h @@ -1,19 +1,19 @@ -// ANSI color escape code definitions. - -#ifdef BBS_COLOR -#define ANSI_RED "\x1b[91m" -#define ANSI_GREEN "\x1b[92m" -#define ANSI_YELLOW "\x1b[93m" -#define ANSI_BLUE "\x1b[94m" -#define ANSI_MAGENTA "\x1b[95m" -#define ANSI_CYAN "\x1b[96m" -#define ANSI_RESET "\x1b[0m" -#else -#define ANSI_RED -#define ANSI_GREEN -#define ANSI_YELLOW -#define ANSI_BLUE -#define ANSI_MAGENTA -#define ANSI_CYAN -#define ANSI_RESET -#endif \ No newline at end of file +// ANSI color escape code definitions. + +#ifdef BBS_COLOR +#define ANSI_RED "\x1b[91m" +#define ANSI_GREEN "\x1b[92m" +#define ANSI_YELLOW "\x1b[93m" +#define ANSI_BLUE "\x1b[94m" +#define ANSI_MAGENTA "\x1b[95m" +#define ANSI_CYAN "\x1b[96m" +#define ANSI_RESET "\x1b[0m" +#else +#define ANSI_RED +#define ANSI_GREEN +#define ANSI_YELLOW +#define ANSI_BLUE +#define ANSI_MAGENTA +#define ANSI_CYAN +#define ANSI_RESET +#endif diff --git a/src/connlist.c b/src/connlist.c index 3e8cf3d..9234a55 100644 --- a/src/connlist.c +++ b/src/connlist.c @@ -1,6 +1,6 @@ // LEMONBBS MODULES: CONNLIST // This module allows for storing connection information statically instead of -// allocating new blocks on every connection and freeing them afterwards. +// allocating on every connection #include #include diff --git a/src/connlist.h b/src/connlist.h index 9d1903e..3edc2aa 100644 --- a/src/connlist.h +++ b/src/connlist.h @@ -7,7 +7,6 @@ struct Connection { uint8_t state; struct LemonClientSocket socket; - pthread_t connThread; int64_t userId; // -1 if not logged in char username[64]; // to reduce db calls }; diff --git a/src/main.c b/src/main.c index ad5875b..e4ff5e8 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ // config values unsigned short configPort; unsigned int configConnlimit; -char *configCertfile, *configKeyfile, *configPassword; +char *configCertfile, *configKeyfile, *configPassword, sslInUse; // return value: 0 = succeeded ; 1 = failed uint8_t initConfigFromFile(const char* configPath) { @@ -37,19 +37,19 @@ uint8_t initConfigFromFile(const char* configPath) { configPort = confPort.u.b; toml_table_t* ssl = toml_table_in(conf, "ssl"); - if (!ssl) {logMessage(error, "Config parsing error: missing [ssl]"); return 1;} + if (ssl) { + toml_datum_t confCertfile = toml_string_in(ssl, "certfile"); + if (!confCertfile.ok) {logMessage(error, "Config parsing error: missing 'certfile' field"); return 1;} + configCertfile = confCertfile.u.s; - toml_datum_t confCertfile = toml_string_in(ssl, "certfile"); - if (!confCertfile.ok) {logMessage(error, "Config parsing error: missing 'certfile' field"); return 1;} - configCertfile = confCertfile.u.s; + toml_datum_t confKeyfile = toml_string_in(ssl, "keyfile"); + if (!confKeyfile.ok) {logMessage(error, "Config parsing error: missing 'keyfile' field"); return 1;} + configKeyfile = confKeyfile.u.s; - toml_datum_t confKeyfile = toml_string_in(ssl, "keyfile"); - if (!confKeyfile.ok) {logMessage(error, "Config parsing error: missing 'keyfile' field"); return 1;} - configKeyfile = confKeyfile.u.s; - - toml_datum_t confPassword = toml_string_in(ssl, "password"); - if (!confPassword.ok) {logMessage(error, "Config parsing error: missing 'password' field"); return 1;} - configPassword = confPassword.u.s; + toml_datum_t confPassword = toml_string_in(ssl, "password"); + if (!confPassword.ok) {logMessage(error, "Config parsing error: missing 'password' field"); return 1;} + configPassword = confPassword.u.s; + } toml_table_t* bbs = toml_table_in(conf, "bbs"); if (!bbs) {logMessage(error, "Config parsing error: missing [bbs]"); return 1;} diff --git a/src/utils.h b/src/utils.h index f997d74..ea3d2d7 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,6 +1,8 @@ #ifndef CHATSERVER_UTILS_H #define CHATSERVER_UTILS_H +#include + #define METASTRING(x) x,sizeof(x)-1 #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x)