-
Notifications
You must be signed in to change notification settings - Fork 0
/
serveHTML.h
76 lines (62 loc) · 1.55 KB
/
serveHTML.h
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
67
68
69
70
71
72
73
74
75
76
#ifndef serveHTML
#define serveHTML
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <stdbool.h>
#define PORT 9999
#define MAX_CONNECTIONS 10
#define PATH_TO_PAGE "/home/albi/Desktop/albi/programmi/Server_in_C"
#define SIZE_MAX 100
#define MAX_MESSAGE_SIZE 100
#define IP_GOOGLE "142.250.200.100"
#define HTML_PORT 80 // 443 con https
#define BUFF 1024
// errors
#define FAIL -1
#define SUCCESS 0
#define handleError(msg) \
do { perror(msg); exit(FAIL); } while (0)
// methods
#define GET 1
#define POST 2
#define PUT 3
#define NOT_SUPPORTED 0
// data structures
typedef int Socket_t; // to represent socket
typedef struct { // to represent address
struct sockaddr_in addr;
socklen_t len;
} Address_t;
typedef struct { // to represent client's request
char uri[BUFF];
unsigned short method;
bool methodSetted;
bool uriSetted;
char *body;
} Request_t;
typedef struct {
char *headers;
char *contenuto;
} Responce_t;
Socket_t initSocket();
Address_t initAddress(bool);
void bindStA(Socket_t, Address_t*);
void listenS(Socket_t);
Socket_t acceptSgA(Socket_t, Address_t*);
Request_t receveFromClient(Socket_t);
Responce_t manageRequest(Request_t);
void sendR(Socket_t, Responce_t);
void child(int);
void serviHTML(char*, int);
char *parseURI(const char*);
char *routeURI(char*);
char *concatenaStringhe(const char*, const char*);
char *fileToText(char*);
#endif