parser_8c.tex
7.48 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
\hypertarget{parser_8c}{
\section{src/http/request/parser.c File Reference}
\label{parser_8c}\index{src/http/request/parser.c@{src/http/request/parser.c}}
}
{\ttfamily \#include $<$string.h$>$}\par
{\ttfamily \#include $<$stdlib.h$>$}\par
{\ttfamily \#include $<$sys/types.h$>$}\par
{\ttfamily \#include \char`\"{}class.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}http/request\_\-parser.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}interface/class.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}interface/stream\_\-reader.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}http/request.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}http/request\_\-queue.h\char`\"{}}\par
Include dependency graph for parser.c:
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item
void \hyperlink{parser_8c_a659e7ea125685d797a099638b3376320}{httpRequestParserParse} (\hyperlink{structHttpRequestParser}{HttpRequestParser})
\item
\hyperlink{parser_8c_a0508cf41efb8d26b8c43116711820d71}{INIT\_\-IFACE} (Class, ctor, dtor, \_\-clone)
\item
\hyperlink{parser_8c_a70f4eea7746a809dd8da71e9cbf4842a}{INIT\_\-IFACE} (StreamReader, get\_\-data)
\item
\hyperlink{parser_8c_a70093dfed29b221273e59f63936237b5}{CREATE\_\-CLASS} (\hyperlink{structHttpRequestParser}{HttpRequestParser}, NULL, IFACE(Class), IFACE(StreamReader))
\end{DoxyCompactItemize}
\subsection{Function Documentation}
\hypertarget{parser_8c_a70093dfed29b221273e59f63936237b5}{
\index{parser.c@{parser.c}!CREATE\_\-CLASS@{CREATE\_\-CLASS}}
\index{CREATE\_\-CLASS@{CREATE\_\-CLASS}!parser.c@{parser.c}}
\subsubsection[{CREATE\_\-CLASS}]{\setlength{\rightskip}{0pt plus 5cm}CREATE\_\-CLASS (
\begin{DoxyParamCaption}
\item[{{\bf HttpRequestParser}}]{, }
\item[{NULL}]{, }
\item[{IFACE(Class)}]{, }
\item[{IFACE(StreamReader)}]{}
\end{DoxyParamCaption}
)}}
\label{parser_8c_a70093dfed29b221273e59f63936237b5}
\hypertarget{parser_8c_a659e7ea125685d797a099638b3376320}{
\index{parser.c@{parser.c}!httpRequestParserParse@{httpRequestParserParse}}
\index{httpRequestParserParse@{httpRequestParserParse}!parser.c@{parser.c}}
\subsubsection[{httpRequestParserParse}]{\setlength{\rightskip}{0pt plus 5cm}void httpRequestParserParse (
\begin{DoxyParamCaption}
\item[{{\bf HttpRequestParser}}]{}
\end{DoxyParamCaption}
)}}
\label{parser_8c_a659e7ea125685d797a099638b3376320}
enqueue current request
remove processed stuff from input buffer.
dont continue loop if input buffer is empty
prepare for next request
Definition at line 43 of file parse.c.
\begin{DoxyCode}
{
static HttpRequest request = NULL;
static char * data; // static pointer to unprocessed data
char * line;
int cont = 1;
while(cont) {
switch(this->state) {
case HTTP_REQUEST_GARBAGE:
data = this->buffer; // initialize static pointer
httpRequestSkip(&data);
request = new(HttpRequest);
this->state = HTTP_REQUEST_START;
break;
case HTTP_REQUEST_START:
if (NULL == (line = httpRequestParserGetLine(&dat
a))) {
cont = 0;
break;
}
httpRequestParserGetRequestLine(request, line);
this->state = HTTP_REQUEST_REQUEST_LINE_DONE;
break;
case HTTP_REQUEST_REQUEST_LINE_DONE:
if (NULL == (line = httpRequestParserGetLine(&dat
a))) {
cont = 0;
break;
}
if (0 == strlen(line)) {
this->state = HTTP_REQUEST_HEADERS_DONE;
break;
}
httpRequestParserGetHeader(request, line);
break;
case HTTP_REQUEST_HEADERS_DONE:
httpHeaderSort(request->header, request->nheader)
;
{
char * nbody;
if (0 == request->nbody) {
nbody = httpHeaderGet(
request->header,
request->nheader,
"Content-Length")
;
if (NULL == nbody) {
this->state =
HTTP_REQUEST_DONE;
break;
}
else {
request->nbody = atoi(nbo
dy);
}
}
if (REMAINS(this, data) >= request->
nbody) {
request->body = calloc(1, request
->nbody + 1);
memcpy(request->body, data, reque
st->nbody);
data += request->nbody;
this->state = HTTP_REQUEST_DONE;
}
}
break;
case HTTP_REQUEST_DONE:
this->request_queue->requests[(this->request_queu
e->nrequests)++] =
request;
memmove(this->buffer, data, REMAINS(this, data));
this->buffer_used -= data - this->buffer;
if (0 == this->buffer_used) {
cont = 0;
}
this->state = HTTP_REQUEST_GARBAGE;
break;
default:
break;
}
}
}
\end{DoxyCode}
Here is the call graph for this function:
\hypertarget{parser_8c_a0508cf41efb8d26b8c43116711820d71}{
\index{parser.c@{parser.c}!INIT\_\-IFACE@{INIT\_\-IFACE}}
\index{INIT\_\-IFACE@{INIT\_\-IFACE}!parser.c@{parser.c}}
\subsubsection[{INIT\_\-IFACE}]{\setlength{\rightskip}{0pt plus 5cm}INIT\_\-IFACE (
\begin{DoxyParamCaption}
\item[{Class}]{, }
\item[{ctor}]{, }
\item[{dtor}]{, }
\item[{\_\-clone}]{}
\end{DoxyParamCaption}
)}}
\label{parser_8c_a0508cf41efb8d26b8c43116711820d71}
\hypertarget{parser_8c_a70f4eea7746a809dd8da71e9cbf4842a}{
\index{parser.c@{parser.c}!INIT\_\-IFACE@{INIT\_\-IFACE}}
\index{INIT\_\-IFACE@{INIT\_\-IFACE}!parser.c@{parser.c}}
\subsubsection[{INIT\_\-IFACE}]{\setlength{\rightskip}{0pt plus 5cm}INIT\_\-IFACE (
\begin{DoxyParamCaption}
\item[{StreamReader}]{, }
\item[{get\_\-data}]{}
\end{DoxyParamCaption}
)}}
\label{parser_8c_a70f4eea7746a809dd8da71e9cbf4842a}