ferencd@0: #include ferencd@0: #include ferencd@0: ferencd@0: #include "web_logmachine.h" ferencd@0: ferencd@0: #include ferencd@0: #include ferencd@0: ferencd@0: #include ferencd@0: #include ferencd@0: ferencd@0: void exit_work(const char* source) ferencd@0: { ferencd@0: log_critical() << "WORK SOURCE:" << source; ferencd@0: } ferencd@0: ferencd@0: void exit_on_error() ferencd@0: { ferencd@0: exit_work("exit_on_error"); ferencd@0: } ferencd@0: ferencd@0: void signal_handler(int signum) ferencd@0: { ferencd@0: log_warning() << "Signal caught " << signum; ferencd@0: exit_work("signal_handler"); ferencd@0: _Exit(1); ferencd@0: } ferencd@0: ferencd@0: void atexit_handler() ferencd@0: { ferencd@0: std::cerr << "Atexit handler" << std::endl; ferencd@0: exit_work("atexit_handler"); ferencd@0: } ferencd@0: ferencd@0: int main(int argc, char* argv[]) ferencd@0: { ferencd@0: std::cout << "thymian 0.1 starting" << std::endl; ferencd@0: (void)argc;(void)argv; ferencd@0: ferencd@0: unafrog::logger::instance().add_log_machine(new web_logmachine); ferencd@0: ferencd@0: info() << "--------------------- App starting [PID:" << getpid() << "] ---------------------"; ferencd@0: ferencd@0: std::set_unexpected (exit_on_error); ferencd@0: std::set_terminate(exit_on_error); ferencd@0: atexit(atexit_handler); ferencd@0: ferencd@0: struct sigaction new_action, old_action; ferencd@0: ferencd@0: /* Set up the structure to specify the new action. */ ferencd@0: new_action.sa_handler = signal_handler; ferencd@0: sigemptyset (&new_action.sa_mask); ferencd@0: new_action.sa_flags = 0; ferencd@0: ferencd@0: sigaction (SIGINT, nullptr, &old_action); ferencd@0: if (old_action.sa_handler != SIG_IGN) ferencd@0: { ferencd@0: sigaction (SIGINT, &new_action, nullptr); ferencd@0: } ferencd@0: ferencd@0: sigaction (SIGHUP, nullptr, &old_action); ferencd@0: if (old_action.sa_handler != SIG_IGN) ferencd@0: { ferencd@0: sigaction (SIGHUP, &new_action, nullptr); ferencd@0: } ferencd@0: ferencd@0: sigaction (SIGTERM, nullptr, &old_action); ferencd@0: if (old_action.sa_handler != SIG_IGN) ferencd@0: { ferencd@0: sigaction (SIGTERM, &new_action, nullptr); ferencd@0: } ferencd@0: ferencd@0: sigaction (SIGSEGV, nullptr, &old_action); ferencd@0: if (old_action.sa_handler != SIG_IGN) ferencd@0: { ferencd@0: sigaction (SIGSEGV, &new_action, nullptr); ferencd@0: } ferencd@0: ferencd@0: sigaction (SIGKILL, nullptr, &old_action); ferencd@0: if (old_action.sa_handler != SIG_IGN) ferencd@0: { ferencd@0: sigaction (SIGKILL, &new_action, nullptr); ferencd@0: } ferencd@0: ferencd@0: srand(static_cast(::time(nullptr))); ferencd@0: ferencd@0: try ferencd@0: { ferencd@0: ferencd@0: if(!config::instance().valid()) ferencd@0: { ferencd@0: log_critical() << "configuration failure, exiting"; ferencd@0: return 1; ferencd@0: } ferencd@0: ferencd@0: // check that all the templates are where they are supposed to be ferencd@0: if(!template_warehouse::instance().checkTemplates()) ferencd@0: { ferencd@0: log_critical() << "Cannot find some templates. Giving up"; ferencd@0: return 1; ferencd@0: } ferencd@0: ferencd@0: // start the web server ferencd@0: tnt::Tntnet app; ferencd@0: app.listen("*", 8999); ferencd@0: ferencd@0: auto pngMap = app.mapUrl("^/img/(.*).png$", "filer"); // the supported images ferencd@0: auto filer1 = app.mapUrl("^/img/(.*).ico$", "filer"); ferencd@0: auto filer2 = app.mapUrl("^/img/(.*).gif$", "filer"); ferencd@0: auto filer3 = app.mapUrl("^/img/(.*).jpg$", "filer"); ferencd@0: auto filer10Global = app.mapUrl("/(.*).js$", "filer"); // javascript handler ferencd@0: auto filerPdf = app.mapUrl("^/pdfs/(.*).pdf$", "filer"); // the PDF downloader ferencd@0: ferencd@0: auto pngMapCurrentTheme = app.mapUrl("^/theme/current/img/(.*).png$", "filer"); // the supported images from the current theme ferencd@0: auto filer1CurrentTheme = app.mapUrl("^/theme/current/img/(.*).ico$", "filer"); ferencd@0: auto filer2CurrentTheme = app.mapUrl("^/theme/current/img/(.*).gif$", "filer"); ferencd@0: auto filer3CurrentTheme = app.mapUrl("^/theme/current/img/(.*).jpg$", "filer"); ferencd@0: auto filer10 = app.mapUrl("^/theme/current/(.*).js$", "filer"); // javascript handler for current theme ferencd@0: auto filer10scriptDirTheme = app.mapUrl("^/theme/current/script/(.*).js$", "filer"); // javascript handler for current theme ferencd@0: auto filer12CurrentTheme = app.mapUrl("/theme/current/(.*).css$", "filer"); // the css files regardless ofwhere they are ferencd@0: auto filer12DirTheme = app.mapUrl("/theme/current/css/(.*).css$", "filer"); // the css files regardless ofwhere they are ferencd@0: ferencd@0: auto filer4 = app.mapUrl("/(.*).png$", "filer"); ferencd@0: auto filer5 = app.mapUrl("/(.*).ico$", "filer"); ferencd@0: auto filer6 = app.mapUrl("/(.*).gif$", "filer"); ferencd@0: auto filer7 = app.mapUrl("/(.*).jpg$", "filer"); ferencd@0: auto filer8 = app.mapUrl("/(.*).html$", "filer"); ferencd@0: auto filer9 = app.mapUrl("/(.*).htm$", "filer"); ferencd@0: auto filer10ScriptDirGlobal = app.mapUrl("/js/(.*).js$", "filer"); // javascript handler ferencd@0: auto filer12 = app.mapUrl("/(.*).css$", "filer"); // the css files regardless ofwhere they are ferencd@0: auto filer12StyleDirGlobal = app.mapUrl("/css/(.*).css$", "filer"); // the css files in a global directory ferencd@0: auto filer13 = app.mapUrl("/robots.txt$", "filer"); ferencd@0: ferencd@0: auto homepage = app.mapUrl("^/$", "root"); // / (ie: homepage) ferencd@0: ferencd@0: auto langNo = app.mapUrl("^/no$", "main_root_sender"); // / (ie: homepage in norwegian) ferencd@0: auto langGb = app.mapUrl("^/gb$", "main_root_sender"); // / (ie: homepage in english) ferencd@0: auto langRo = app.mapUrl("^/ro$", "main_root_sender"); // / (ie: homepage in romanian) ferencd@0: auto langHu = app.mapUrl("^/hu$", "main_root_sender"); // / (ie: homepage in hungarian) ferencd@0: ferencd@0: auto categoryLister = app.mapUrl("^/l/(.*)", "category_root_sender"); // / (ie: lists of various food categories) ferencd@0: ferencd@0: auto recipeSender = app.mapUrl("^/r/(.*)", "r"); // / (ie: the recipes themselves) ferencd@0: ferencd@0: ferencd@0: app.run(); ferencd@0: } ferencd@0: catch (const std::exception& e) ferencd@0: { ferencd@0: emergency() << e.what(); ferencd@0: exit(1); ferencd@0: } ferencd@0: log_critical() << "bye bye cruel world"; ferencd@0: exit(0); ferencd@0: }