-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.h
66 lines (59 loc) · 1.4 KB
/
server.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
#include <sys/socket.h>
#include <errno.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <fcntl.h>
#define PORT_NUM 8080
#define BUFF_SIZE 20000
#define BACKLOG 100
#define HTML_FILE "text/html"
#define IMG_JPEG_FILE "image/jpeg"
#define PDF_FILE "application/pdf"
extern const char *FMT;
typedef enum
{
GET,
POST,
PUT
} ReqType;
/// Route has request type, host address, requested resource(route) and userstring
typedef struct
{
ReqType type;
char *route;
char *host;
char *user_string;
} Route;
typedef struct
{
int *socket;
char *host_name;
} thread_args;
typedef struct
{
unsigned char *buffer;
struct stat fp;
char *filetype;
} FileOut;
void *get_in_addr(struct sockaddr *sa);
void check(int value, char *err_str);
void *handle_conn_wrapper(void *arg);
void handle_new_conn(int *accepted_socket, void *additional_args);
Route *parse_http(char *input);
Route *parse_route(char *input, Route *req);
char *humanize(Route *route, pid_t *pid);
void pretty_print_route(Route *route);
char *translate_reqtype(ReqType type);
int read_file(Route *route, FileOut *out);
void write_file(FileOut *out, int sockfd);
char *parse_file_type(char *input);
void free_fout(FileOut *out);
void setnonblocking(int fd);