-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpenguen.c
More file actions
56 lines (45 loc) · 1.1 KB
/
penguen.c
File metadata and controls
56 lines (45 loc) · 1.1 KB
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
#include <stdio.h>
#include <stdlib.h>
#include "http.h"
#include "conf.h"
#include "parser.h"
#include "lexer.h"
#include "error.h"
int pgn_be_verbose = 0;
int main(int argc, char **argv)
{
int rc;
if (argc < 2)
{
fprintf(stderr, "Please specify a configuration file!\n");
exit(EXIT_FAILURE);
}
if (argc > 2 && strcmp(argv[2], "-v") == 0)
pgn_be_verbose = 1;
yyin = fopen(argv[1], "r");
pgn_conf.addr = "0.0.0.0";
pgn_conf.port = 80;
pgn_conf.flags = 0;
pgn_conf.routes = NULL;
pgn_conf.static_dir = NULL;
yyparse();
fclose(yyin);
pgn_http_server_t *server = pgn_http_create_server(&pgn_conf);
if (server == NULL)
{
pgn_print_error();
exit(EXIT_FAILURE);
}
fprintf(stderr, "Penguen listens for requests at http://%s:%d\n", pgn_conf.addr, pgn_conf.port);
rc = pgn_http_listen(server);
if (rc != 0)
{
pgn_print_error();
free(server);
pgn_conf_free(&pgn_conf);
exit(EXIT_FAILURE);
}
free(server);
pgn_conf_free(&pgn_conf);
exit(EXIT_SUCCESS);
}