-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
66 lines (57 loc) · 1.6 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
62
63
64
65
66
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include "Network/Server.h"
#include "Routing/Routing.h"
#include "HTTP_status/HTTP_status.h"
void listUsers(int client_socket)
{
char json[300];
snprintf(json, sizeof(json),
"{"
" \"index\": \"hello\""
"}");
if (response(client_socket, HTTP_STATUS_OK, json) < 0)
{
perror("something happenned...\n");
response(client_socket, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
}
}
void createUser(int client_socket)
{
char json[300];
snprintf(json, sizeof(json),
"{"
" \"index\": \"users created\""
"}");
if (response(client_socket, HTTP_STATUS_OK, json) < 0)
{
perror("something happenned...\n");
response(client_socket, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
}
}
void handler_second(int client_socket)
{
char json[300];
snprintf(json, sizeof(json),
"{"
" \"index\": \"hello\""
"}");
if (response(client_socket, HTTP_STATUS_OK, json) < 0)
{
perror("something happenned...\n");
response(client_socket, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
}
}
int main()
{
struct Server server = server_constructor(AF_INET, SOCK_STREAM, 0, INADDR_ANY, 8080, 10);
RouteNode *root = newNode("/");
addRouteNode(root, "/users", "GET", listUsers);
addRouteNode(root, "/users/create", "POST", createUser);
addRouteNode(root, "/users/create/something", "POST", NULL);
start(&server, root);
free(root);
return 0;
}