-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.h
84 lines (68 loc) · 2.47 KB
/
tools.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
#ifndef TOOLS_H
#define TOOLS_H
#define ERR 0
#define GET 1
#define POST 2
#define BUF_SIZE 1024
#define HEADER_LIST_INCREASE_FACTOR 5 // HTML Message의 header list 동적 할당 size는 5씩 증가한다.
struct URL
{
char *ip;
char *port;
char *path;
};
struct HttpHeader
{
char *key;
char *value;
};
struct HttpHeaderList
{
struct HttpHeader **headers;
int length;
int max_length;
};
struct HttpRequestMessage
{
int method;
char *ip;
char *port;
char *path;
char *version;
int contentLength;
int headerLength;
struct HttpHeaderList *hList; // 헤더 list를 저장하는 배열
char *body; // 첫 번째 헤더 메세지 fragment에서 body의 시작 포인터를 가진다.
};
struct HttpResponseMessage
{
char *version;
char *status;
struct HttpHeaderList *hList;
int contentLength;
char *body;
};
char* str_alloc(int length);
char* makeString(char str[]); // str을 문자열로 가지는 char*를 allocation해서 return
char* copyString(char *str);
void substr(char *dest, char *start, char *end);
void clearString(char *str);
char* makeHost(struct URL *url); // URL을 받아 ip:port 형식의 host를 만들어준다.
struct HttpHeader* createHeader(char *key, char *value);
struct HttpHeaderList* createHeaderList();
struct HttpRequestMessage* createRequestMessage(int method, struct URL *url, char *version, char *body, int contentLength);
struct HttpResponseMessage* createResponseMessage(char *version, char *status, int CL);
char* makeRequestHeaderString(struct HttpRequestMessage *target); // RequestMessage를 byte-string으로 변환해준다.
char* makeResponseHeaderString(struct HttpResponseMessage *target);
struct HttpRequestMessage* parseRequestMessage(char *message); // String을 파싱해 HttpRequestMessage로 만들어준다.
void addHeader(struct HttpHeaderList* hList, char *key, char *value);
struct HttpHeader* getHeader(struct HttpHeaderList* hList, int index);
void freeURL(struct URL *url);
void freeHeader(struct HttpHeader* target); // HttpHeader를 free한다. 이 때 key와 value pointer도 free하므로 매우 주의해야 한다.
void freeHeaderList(struct HttpHeaderList* target);
void freeRequestMessage(struct HttpRequestMessage* target);
void freeResponseMessage(struct HttpResponseMessage* target);
void printHeader(struct HttpHeader *target); // target을 print 합니다. (debugging function)
void printHeaderList(struct HttpHeaderList *target, char *comment);
void printRequestMessage(struct HttpRequestMessage *target, char *comment);
#endif