-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebng.h
executable file
·104 lines (83 loc) · 2.16 KB
/
webng.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* This is the file that defines our structures used in our functions, here
* we have the cryptographic key, encrypting requests; the request struct
* to hold the information pertaining to a request; and the response struct
* holding the response information.
*/
#ifndef WEBNG_H
#define WEBNG_H
/*
* Objects definitions
*/
/* Our structure that contains the response's data */
struct response {
short status;
char *stext;
char *type;
char *path;
float vers;
char *serv;
char *date;
char *conn;
char *auth;
char *key;
char *cenc;
char *ctype;
int clen;
char *ttype;
char *body;
};
/* Our structure that contains the request's data */
struct request {
char *type;
char *url;
float vers;
char *host;
char *conn;
char *user;
char *auth;
char *key;
char *cenc;
char *ctype;
int clen;
char *ttype;
char *body;
};
struct url {
char *proto;
char *ip;
char *port;
char *domain;
char *path;
char *pars;
};
/*
* Function prototypes
*/
/* Reads data in chunked format from a socket */
void read_chunks(int conn, char *body);
/* Reads data in the HTTP header format from a socket */
void get_header(int conn, char **buffer);
/* Extracts a token from a string */
char *get_token(char *source, char *par);
/* Extracts the path from an URL */
short parse_URL(char *url, struct url *addr);
/* Parses a string and populates the request structure */
short parse_request(char *message, struct request *req);
/* Parses a string and populates the response structure */
short parse_response(char *message, struct response *res);
/* Calculates a request header size */
short req_header_len(struct request req);
/* Creates a HTTP header string */
short create_req_header(struct request req, char *dest);
/* Calculates a response header size */
short res_header_len(struct response res);
/* Creates a response with header and optional body */
short create_res_header(struct response res, char *dest);
/* Parses a list of numbers from a string to an array */
short *split_keys(char *key_list);
/* Reads a message and encodes it */
short encode(char *message, char *key);
/* Reads an encrypted message and decodes it */
short decode(char *cypher, char *key);
#endif