torrent-stats/torrent-stats.c

50 lines
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "configfile.h"
#include "connection.h"
#include "event.h"
#include "httpd.h"
#include "list.h"
#include "logging.h"
#include "sockaddr.h"
#include "tcpsocket.h"
static int listen_cb(const char *parameter, void *privdata)
{
struct sockaddr_in addr;
if (parse_sockaddr(parameter, &addr) < 0) {
log_print(LOG_WARN, "listen_cb(): invalid address");
return -1;
}
int sockfd = tcp_listen(&addr);
if (sockfd < 0) {
log_print(LOG_WARN, "listen_cb(): tcp_listen()");
return -1;
}
log_print(LOG_INFO, "listen on %s", get_sockaddr_buf(&addr));
event_add_readfd(NULL, sockfd, privdata, NULL);
return 0;
}
int main(int argc, char *argv[])
{
if (config_parse("torrent-stats.conf") < 0)
return 1;
config_get_strings("global", "listen", listen_cb, ctcs_accept_handler);
config_get_strings("global", "listen-http", listen_cb, httpd_accept_handler);
httpd_add_cb("/", 1, ctcs_httpd_handler, NULL);
struct timeval tv = { .tv_sec = 10, .tv_usec = 0 };
event_add_timeout(&tv, ctcs_trigger_status, NULL);
event_loop();
return 0;
}