You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
7.5 KiB
199 lines
7.5 KiB
\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}
|