#include "messenger.hpp" #include "color.hpp" #include #include #include #include #define STDOUT_REDIRECTION_FILE VAR_DIRECTORY "/.stdout" #define STDERR_REDIRECTION_FILE VAR_DIRECTORY "/.stderr" static char* appname = nullptr; static bool is_server = true; static bool debug = false; static int max_clients = 10; static const char* mariadb_login = MARIADB_DEFAULT_LOGIN; static const char* mariadb_password = MARIADB_DEFAULT_PASSWORD; static bool create_users_table = false; static inet::inet_address address = {in_addr{INADDR_ANY}, DEFAULT_PORT}; static msg::HEADER::signal operation_signal = msg::HEADER::s_zero; static char* login; static char* password; static char* metadata; static int idatapipe = -1; static int odatapipe = -1; static constexpr const char* s_options = "m:a:o:l:p:M:I:O:c:dVv?"; const option l_options[]{ {"mode", required_argument, nullptr, 'm'}, {"address", required_argument, nullptr, 'a'}, {"operation", required_argument, nullptr, 'o'}, {"login", required_argument, nullptr, 'l'}, {"password", required_argument, nullptr, 'p'}, {"metadata", required_argument, nullptr, 'M'}, {"idatapipe", required_argument, nullptr, 'I'}, {"odatapipe", required_argument, nullptr, 'O'}, {"max-clients", required_argument, nullptr, 'c'}, {"dblogin", required_argument, nullptr, 2}, {"dbpassword", required_argument, nullptr, 3}, {"create-tbl", no_argument, nullptr, 1}, {"constant", optional_argument, nullptr, 10}, {"debug", no_argument, nullptr, 'd'}, {"verbose", no_argument, nullptr, 'V'}, {"version", no_argument, nullptr, 'v'}, {"help", no_argument, nullptr, '?'}, {nullptr} }; inline static void help(int code); inline static void daemonize_application(); void opensyslog(); inline static void sighandle_close_port(int sig); inline static void run_server(); inline static void run_client(); template inline static void wr_pipe(const T& val) { ::write(odatapipe, &val, sizeof val); } template inline static void rd_pipe(T& val) { ::read(idatapipe, &val, sizeof val); } template