summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authortiptorrent development team <tiptorrent@soleta.eu>2021-08-17 00:05:31 +0200
committertiptorrent development team <tiptorrent@soleta.eu>2021-09-29 15:47:43 +0200
commit2610239d62d744294e55d44e46937bd6dea87559 (patch)
treea14c9da8d4156e31cd311b036287e7aa9c90a40f /src/main.c
initial commit
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..fd543a2
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2020-2021 Soleta Networks <info@soleta.eu>
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU Affero General Public License as published by the
+ * Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ */
+
+#include "core.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <ifaddrs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <netinet/tcp.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <getopt.h>
+
+int max_clients = DEFAULT_MAX_CLIENTS;
+const char *root = ".";
+bool redirect;
+
+static struct option tip_repo_opts[] = {
+ { "max-clients", 1, 0, 'n' },
+ { "redirect", 0, 0, 'r' },
+ { "root", 1, 0, 't' },
+ { NULL },
+};
+
+struct ev_io ev_io_server_rest;
+
+int main(int argc, char *argv[])
+{
+ int socket_rest, val;
+
+ openlog("tiptorrent", LOG_PID, LOG_DAEMON);
+
+ tip_main_loop = ev_default_loop(0);
+
+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
+ exit(EXIT_FAILURE);
+
+ while (1) {
+ val = getopt_long(argc, argv, "n:r", tip_repo_opts, NULL);
+ if (val < 0)
+ break;
+
+ switch (val) {
+ case 'n':
+ max_clients = atoi(optarg);
+ if (max_clients <= 0) {
+ syslog(LOG_ERR, "Invalid number for max_clients");
+ return EXIT_FAILURE;
+ }
+ break;
+ case 'r':
+ redirect = true;
+ break;
+ case 't':
+ root = strdup(optarg);
+ break;
+ case '?':
+ return EXIT_FAILURE;
+ default:
+ break;
+ }
+ }
+
+ socket_rest = tip_socket_server_init("9999");
+ if (socket_rest < 0) {
+ syslog(LOG_ERR, "Cannot open tiptorrent server socket\n");
+ exit(EXIT_FAILURE);
+ }
+
+ ev_io_init(&ev_io_server_rest, tip_server_accept_cb, socket_rest, EV_READ);
+ ev_io_start(tip_main_loop, &ev_io_server_rest);
+
+ syslog(LOG_INFO, "Waiting for connections\n");
+
+ while (1)
+ ev_loop(tip_main_loop, 0);
+
+ exit(EXIT_SUCCESS);
+}