-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.c
46 lines (40 loc) · 1.23 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
#include "src/protocolutils.h"
#include "src/socketutils.h"
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
char *Homepage (request_t *req) {
// JSON response example
// char *r = parseresponse("200 OK", "application/json", "{\"sector\":\"Solar System\",\"planet\":\"Mars\",\"site\":\"Olympus Mons\"}", r);
char *r;
r = parseresponse(
"200 OK",
"text/html",
"<html><h1>It is alive!</h1></html>",
512,
r);
return r;
}
char *DefaultRoute (request_t *req) {
char *r;
r = parseresponse(
"404 Not Found",
"text/html",
"<html><h1>404 Not Found</h1><br><b>Ptahka</b> did not find the requested resource.</html>",
512,
r);
return r;
}
int main (int argc,char *argv[]) {
table_t *table = inittable();
createroute("GET", "/home", &Homepage, table);
printf("127.0.0.1:7070\n");
initservice(&parserequest,
table,
&executeroute,
&DefaultRoute);
// It does all the job freeing the routing table contents
freetable(table);
return 0;
}