-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
61 lines (57 loc) · 1.68 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "stdio.h"
#include "stdlib.h"
#include "sys/types.h"
#include "sys/select.h"
#include "sys/socket.h"
#include "microhttpd.h"
#include "utils.h"
#include "defaults.h"
#include "logger.h"
#include "controller.h"
char *hostname;
int main() {
hostname = (char *)malloc(DEFAULT_HOSTNAME_BUFFER_SIZE + 1);
print_banner();
uint32_t port = get_port();
uint32_t threads = get_thread_pool_size();
get_hostname(hostname);
#ifdef DEBUG
log_message(stdout, "[ENV]: Development\r\n");
#else
log_message(stdout, "[ENV]: Release\r\n");
#endif
log_message(stdout, "[LOG]: Initializing white-rabbit with:\r\n");
log_message(stdout, "\t├─ PORT=%d\r\n", port);
log_message(stdout, "\t├─ THREAD_POOL_SIZE_KEY=%d\r\n", threads);
#if EPOLL_SUPPORT
log_message(stdout, "\t├─ EPOLL_SUPPORT\r\n");
#endif
log_message(stdout, "\t└─ hostname=%s\r\n\n", hostname);
// Daemon
struct MHD_Daemon *daemon;
daemon = MHD_start_daemon(
// MHD_FEATURE
MHD_USE_SELECT_INTERNALLY
#if DEBUG
| MHD_USE_DEBUG
#endif
#if EPOLL_SUPPORT
| MHD_USE_EPOLL_LINUX_ONLY
#endif
,
port, NULL, NULL,
&answer_to_connection, NULL,
// MHD_OPTION
MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) threads,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) DEFAULT_TIME_OUT,
MHD_OPTION_END);
if (NULL == daemon)
return 1;
log_message(stdout, "[LOG]: (/¯◡ ‿ ◡)/¯ wh1t3-r4bb1t listening...\r\n");
getchar();
log_message(stdout, "[LOG]: Killing daemon\r\n");
MHD_stop_daemon (daemon);
log_message(stdout, "[LOG]: Freeing allocated variables\r\n");
free(hostname);
return 0;
}