2012-09-12 10:18:51 +02:00
|
|
|
#include "plugin.h"
|
|
|
|
|
2012-02-28 14:44:00 +01:00
|
|
|
// Transport includes
|
2015-11-18 14:05:57 +01:00
|
|
|
#include "transport/Config.h"
|
|
|
|
#include "transport/NetworkPlugin.h"
|
|
|
|
#include "transport/Logging.h"
|
2012-02-28 14:44:00 +01:00
|
|
|
|
|
|
|
// Swiften
|
|
|
|
#include "Swiften/Swiften.h"
|
|
|
|
|
2012-04-13 17:43:35 +04:00
|
|
|
#ifndef _WIN32
|
2012-02-28 14:44:00 +01:00
|
|
|
// for signal handler
|
|
|
|
#include "unistd.h"
|
|
|
|
#include "signal.h"
|
|
|
|
#include "sys/wait.h"
|
|
|
|
#include "sys/signal.h"
|
2012-03-21 19:17:43 +04:00
|
|
|
#endif
|
2012-02-28 14:44:00 +01:00
|
|
|
// Boost
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
using namespace boost::filesystem;
|
|
|
|
using namespace boost::program_options;
|
|
|
|
using namespace Transport;
|
|
|
|
|
2012-04-13 17:43:35 +04:00
|
|
|
#ifndef _WIN32
|
2012-03-03 16:07:41 +04:00
|
|
|
|
2012-02-28 14:44:00 +01:00
|
|
|
static void spectrum_sigchld_handler(int sig)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
do {
|
|
|
|
pid = waitpid(-1, &status, WNOHANG);
|
|
|
|
} while (pid != 0 && pid != (pid_t)-1);
|
|
|
|
|
|
|
|
if ((pid == (pid_t) - 1) && (errno != ECHILD)) {
|
|
|
|
char errmsg[BUFSIZ];
|
|
|
|
snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid);
|
|
|
|
perror(errmsg);
|
|
|
|
}
|
|
|
|
}
|
2012-03-03 16:07:41 +04:00
|
|
|
#endif
|
2012-02-28 14:44:00 +01:00
|
|
|
|
|
|
|
int main (int argc, char* argv[]) {
|
|
|
|
std::string host;
|
|
|
|
int port;
|
|
|
|
|
2012-04-13 17:43:35 +04:00
|
|
|
#ifndef _WIN32
|
2012-02-28 14:44:00 +01:00
|
|
|
if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) {
|
|
|
|
std::cout << "SIGCHLD handler can't be set\n";
|
|
|
|
return -1;
|
|
|
|
}
|
2012-03-03 16:07:41 +04:00
|
|
|
#endif
|
2012-02-28 14:44:00 +01:00
|
|
|
|
2012-09-04 14:58:04 +02:00
|
|
|
std::string error;
|
|
|
|
Config *cfg = Config::createFromArgs(argc, argv, error, host, port);
|
|
|
|
if (cfg == NULL) {
|
|
|
|
std::cerr << error;
|
2012-02-28 14:44:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-09-04 14:58:04 +02:00
|
|
|
Logging::initBackendLogging(cfg);
|
2012-02-28 14:44:00 +01:00
|
|
|
|
|
|
|
Swift::SimpleEventLoop eventLoop;
|
2012-09-12 10:18:51 +02:00
|
|
|
Plugin p(cfg, &eventLoop, host, port);
|
|
|
|
eventLoop.run();
|
2012-02-28 14:44:00 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|