#include #include #include #include #include #include #include #include static HttpServer *server = NULL; static void SignalHandler(int signal) { size_t i; switch (signal) { case SIGPIPE: return; case SIGTERM: case SIGINT: if (!server) { return; } HttpServerStop(server); break; } } int Main(void) { HttpServerConfig conf; ParseeData *data; const ParseeConfig *parsee_conf; Stream *yaml; XMPPComponent *jabber; struct sigaction sigAction; Log(LOG_INFO, "%s - v%s", NAME, VERSION); ParseeConfigLoad("parsee.json"); ParseeConfigInit(); yaml = StreamOpen("parsee.yaml", "w"); ParseeExportConfigYAML(yaml); StreamClose(yaml); parsee_conf = ParseeConfigGet(); { jabber = XMPPInitialiseCompStream( parsee_conf->component_host, parsee_conf->component_port ); XMPPAuthenticateCompStream( jabber, parsee_conf->shared_comp_secret ); } Log(LOG_INFO, "HS token: %s", parsee_conf->hs_token); ASRegisterUser(parsee_conf, parsee_conf->sender_localpart); memset(&conf, 0, sizeof(conf)); conf.port = parsee_conf->port; conf.threads = 4; conf.maxConnections = 32; conf.handlerArgs = ParseeInitData(jabber); conf.handler = ParseeRequest; sigAction.sa_handler = SignalHandler; sigfillset(&sigAction.sa_mask); sigAction.sa_flags = SA_RESTART; #define SIGACTION(sig, act, oact) \ if (sigaction(sig, act, oact) < 0) \ { \ Log(LOG_ERR, "Unable to install signal handler: %s", #sig); \ } \ else \ { \ Log(LOG_DEBUG, "Installed signal handler: %s", #sig); \ } SIGACTION(SIGINT, &sigAction, NULL); SIGACTION(SIGTERM, &sigAction, NULL); SIGACTION(SIGPIPE, &sigAction, NULL); SIGACTION(SIGUSR1, &sigAction, NULL); #undef SIGACTION /* TODO: The rest of Parsee. */ server = HttpServerCreate(&conf); HttpServerStart(server); /* TODO: Manage signals(^C) with finesse */ HttpServerJoin(server); HttpServerFree(server); ParseeConfigFree(); ParseeFreeData(conf.handlerArgs); return 0; }