ReactOS 0.4.16-dev-122-g325d74c
CHttpParser Class Reference

#include <http.h>

Public Member Functions

 CHttpParser ()
 
 ~CHttpParser ()
 
BOOL Complete ()
 
BOOL Parse ()
 

Public Attributes

CHAR sBuffer [2048]
 
UINT nHead
 
UINT nTail
 
CHAR sUri [255]
 
CHAR sVersion [15]
 
CHAR sHeader [63]
 
CHAR sMethod [63]
 
UINT nMethodNo
 
BOOL bUnknownMethod
 
BOOL bBadRequest
 

Private Member Functions

BOOL ReadChar (LPSTR lpsStr)
 
BOOL PeekChar (LPSTR lpsStr)
 
BOOL ReadString (LPSTR lpsStr, UINT nLength)
 
BOOL ReadSpecial (LPSTR lpStr, UINT nLength)
 
VOID Skip (CHAR sStr)
 
BOOL Expect (CHAR sStr)
 
BOOL ExpectCRLF ()
 
BOOL RequestLine ()
 
BOOL GenerelHeader ()
 
BOOL RequestHeader ()
 
BOOL EntityHeader ()
 
BOOL MessageBody ()
 

Detailed Description

Definition at line 26 of file http.h.

Constructor & Destructor Documentation

◆ CHttpParser()

CHttpParser::CHttpParser ( )

Definition at line 37 of file http.cpp.

38{
39 nHead = 0;
40 nTail = 0;
41}
UINT nTail
Definition: http.h:30
UINT nHead
Definition: http.h:29

◆ ~CHttpParser()

CHttpParser::~CHttpParser ( )

Definition at line 44 of file http.cpp.

45{
46}

Member Function Documentation

◆ Complete()

BOOL CHttpParser::Complete ( )

Definition at line 49 of file http.cpp.

50{
51 UINT nTmp;
52
53 /*DPRINT("--1:-%d---\n", sBuffer[nHead-2]);
54 DPRINT("--2:-%d---\n", sBuffer[nHead-1]);
55
56 sBuffer[nHead] = '!';
57 sBuffer[nHead+1] = 0;
58 DPRINT("Examining buffer: (Head: %d, Tail: %d)\n", nHead, nTail);
59 DPRINT("%s\n", (LPSTR)&sBuffer[nTail]);*/
60
61 nTmp = nTail;
62 if (!Parse()) {
63 if (!bUnknownMethod)
64 nTail = nTmp;
65 return FALSE;
66 } else
67 return TRUE;
68}
BOOL Parse()
Definition: http.cpp:191
BOOL bUnknownMethod
Definition: http.h:36
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int UINT
Definition: ndis.h:50

Referenced by CHttpClient::OnRead().

◆ EntityHeader()

BOOL CHttpParser::EntityHeader ( )
private

Definition at line 350 of file http.cpp.

351{
352 INT i;
353
354 for (i = 0; i < NUMENTITIES; i++) {
355 if (strcmp(EntityTable[i], sHeader) == 0) {
356 switch (i) {
357 case 0:
358 default: {
359 //cout << "<Entity-Header>: #" << i << endl;
360 Expect(':');
361 Expect(' ');
362 Skip(13);
363 ExpectCRLF();
364 return TRUE;
365 }
366 }
367 return FALSE;
368 }
369 }
370 return FALSE;
371}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
BOOL Expect(CHAR sStr)
Definition: http.cpp:170
BOOL ExpectCRLF()
Definition: http.cpp:184
CHAR sHeader[63]
Definition: http.h:33
VOID Skip(CHAR sStr)
Definition: http.cpp:161
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
CHAR EntityTable[NUMENTITIES][17]
Definition: http.cpp:30
#define NUMENTITIES
Definition: http.h:15
int32_t INT
Definition: typedefs.h:58

Referenced by Parse().

◆ Expect()

BOOL CHttpParser::Expect ( CHAR  sStr)
private

Definition at line 170 of file http.cpp.

171{
172 CHAR sTmp;
173
174 if (PeekChar(&sTmp)) {
175 if (sTmp == sCh) {
176 ReadChar(&sTmp);
177 return TRUE;
178 }
179 }
180 return FALSE;
181}
BOOL PeekChar(LPSTR lpsStr)
Definition: http.cpp:98
BOOL ReadChar(LPSTR lpsStr)
Definition: http.cpp:72
char CHAR
Definition: xmlstorage.h:175

Referenced by EntityHeader(), ExpectCRLF(), GenerelHeader(), RequestHeader(), and RequestLine().

◆ ExpectCRLF()

BOOL CHttpParser::ExpectCRLF ( )
private

Definition at line 184 of file http.cpp.

185{
186 return (Expect(13) && Expect(10));
187}

Referenced by EntityHeader(), GenerelHeader(), Parse(), RequestHeader(), and RequestLine().

◆ GenerelHeader()

BOOL CHttpParser::GenerelHeader ( )
private

Definition at line 253 of file http.cpp.

254{
255 INT i;
256
257 for (i = 0; i < NUMGENERELS; i++) {
258 if (strcmp(GenerelTable[i], sHeader) == 0) {
259 switch (i) {
260 case 1: {
261 //Connection
262 Expect(':');
263 Expect(' ');
264 Skip(13);
265 ExpectCRLF();
266 break;
267 }
268 default: {
269 Expect(':');
270 Expect(' ');
271 Skip(13);
272 ExpectCRLF();
273 }
274 }
275 return TRUE;
276 }
277 }
278 return FALSE;
279}
CHAR GenerelTable[NUMGENERELS][18]
Definition: http.cpp:22
#define NUMGENERELS
Definition: http.h:13

Referenced by Parse().

◆ MessageBody()

BOOL CHttpParser::MessageBody ( )
private

Definition at line 374 of file http.cpp.

375{
376 return FALSE;
377}

Referenced by Parse().

◆ Parse()

BOOL CHttpParser::Parse ( )

Definition at line 191 of file http.cpp.

192{
193 BOOL bStatus;
194
195 if (RequestLine()) {
196 do {
197 if (!ReadString(sHeader, sizeof(sHeader)))
198 break;
199 bStatus = (GenerelHeader());
200 bStatus = (RequestHeader() || bStatus);
201 bStatus = (EntityHeader() || bStatus);
202 } while (bStatus);
203 // CRLF
204 if (!ExpectCRLF())
205 return FALSE;
206 MessageBody();
207 return TRUE;
208 }
209 return FALSE;
210}
BOOL GenerelHeader()
Definition: http.cpp:253
BOOL MessageBody()
Definition: http.cpp:374
BOOL RequestHeader()
Definition: http.cpp:285
BOOL RequestLine()
Definition: http.cpp:213
BOOL ReadString(LPSTR lpsStr, UINT nLength)
Definition: http.cpp:116
BOOL EntityHeader()
Definition: http.cpp:350
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by Complete().

◆ PeekChar()

BOOL CHttpParser::PeekChar ( LPSTR  lpsStr)
private

Definition at line 98 of file http.cpp.

99{
100 UINT nFakeTail;
101
102 if (nTail == sizeof(sBuffer))
103 nFakeTail = 0;
104 else
105 nFakeTail = nTail;
106 if (nFakeTail != nHead) {
107 lpsStr[0] = sBuffer[nFakeTail];
108 return TRUE;
109 } else {
110 lpsStr[0] = 0;
111 return FALSE;
112 }
113}
CHAR sBuffer[2048]
Definition: http.h:28

Referenced by Expect(), ReadSpecial(), ReadString(), RequestLine(), and Skip().

◆ ReadChar()

BOOL CHttpParser::ReadChar ( LPSTR  lpsStr)
private

Definition at line 72 of file http.cpp.

73{
74 if (nTail <= nHead) {
75 if (nTail != nHead) {
76 lpsStr[0] = sBuffer[nTail];
77 nTail++;
78 return TRUE;
79 } else {
80 lpsStr[0] = 0;
81 return FALSE;
82 }
83 } else {
84 if (nTail == sizeof(sBuffer))
85 nTail = 0;
86 if (nTail != nHead) {
87 lpsStr[0] = sBuffer[nTail];
88 nTail++;
89 return TRUE;
90 } else {
91 lpsStr[0] = 0;
92 return FALSE;
93 }
94 }
95}

Referenced by Expect(), ReadSpecial(), ReadString(), and Skip().

◆ ReadSpecial()

BOOL CHttpParser::ReadSpecial ( LPSTR  lpStr,
UINT  nLength 
)
private

Definition at line 142 of file http.cpp.

143{
144 UINT i = 0;
145 CHAR sTmp;
146
147 while (PeekChar(&sTmp) && (sTmp != ' ') && (sTmp != 13)) {
148 if (i >= (nLength - 1)) {
149 lpsStr[nLength - 1] = 0;
150 return FALSE;
151 }
152 ReadChar(&sTmp);
153 lpsStr[i] = sTmp;
154 i++;
155 }
156 lpsStr[i] = 0;
157 return TRUE;
158}
_In_ DWORD nLength
Definition: wincon.h:473

Referenced by RequestLine().

◆ ReadString()

BOOL CHttpParser::ReadString ( LPSTR  lpsStr,
UINT  nLength 
)
private

Definition at line 116 of file http.cpp.

117{
118 UINT i = 0;
119 CHAR sTmp;
120
121 while (PeekChar(&sTmp)) {
122 if (((sTmp >= 'A') && (sTmp <= 'Z')) || ((sTmp >= 'a') && (sTmp <= 'z')) ||
123 ((sTmp >= '0') && (sTmp <= '9')) || (sTmp == '-')) {
124 if (i >= (nLength - 1)) {
125 lpsStr[0] = 0;
126 return FALSE;
127 }
128 ReadChar(&sTmp);
129 lpsStr[i] = sTmp;
130 i++;
131 } else {
132 lpsStr[i] = 0;
133 return TRUE;
134 }
135 }
136 lpsStr[0] = 0;
137 return FALSE;
138}

Referenced by Parse(), and RequestLine().

◆ RequestHeader()

BOOL CHttpParser::RequestHeader ( )
private

Definition at line 285 of file http.cpp.

286{
287 INT i;
288
289 for (i = 0; i < NUMREQUESTS; i++) {
290 if (strcmp(RequestTable[i], sHeader) == 0) {
291 switch (i) {
292 case 0: {
293 //Accept
294 Expect(':');
295 Expect(' ');
296 Skip(13);
297 ExpectCRLF();
298 break;
299 }
300 case 2: {
301 //Accept-Encoding
302 Expect(':');
303 Expect(' ');
304 Skip(13);
305 ExpectCRLF();
306 break;
307 }
308 case 3: {
309 //Accept-Language
310 Expect(':');
311 Expect(' ');
312 Skip(13);
313 ExpectCRLF();
314 break;
315 }
316 case 6: {
317 //Host
318 Expect(':');
319 Expect(' ');
320 Skip(13);
321 ExpectCRLF();
322 break;
323 }
324 case 16: {
325 //User-Agent
326 Expect(':');
327 Expect(' ');
328 Skip(13);
329 ExpectCRLF();
330 break;
331 }
332 default: {
333 Expect(':');
334 Expect(' ');
335 Skip(13);
336 ExpectCRLF();
337 return TRUE;
338 }
339 }
340 return TRUE;
341 }
342 }
343 return FALSE;
344}
CHAR RequestTable[NUMREQUESTS][20]
Definition: http.cpp:25
#define NUMREQUESTS
Definition: http.h:14

Referenced by Parse().

◆ RequestLine()

BOOL CHttpParser::RequestLine ( )
private

Definition at line 213 of file http.cpp.

214{
215 CHAR sCh;
216 UINT i;
217
219
220 // RFC 2068 states that servers SHOULD ignore any empty nine(s) received where a
221 // Request-Line is expected
222 while (PeekChar(&sCh) && ((sCh == 13) || (sCh == 10)));
223
224 if (!ReadString(sMethod, sizeof(sMethod)))
225 return FALSE;
226
227 for (i = 0; i < NUMMETHODS; i++) {
228 if (strcmp(MethodTable[i], sMethod) == 0) {
229 nMethodNo = i;
230 if (!Expect(' '))
231 return FALSE;
232 // URI (ie. host/directory/resource)
233 if (!ReadSpecial(sUri, sizeof(sUri)))
234 return FALSE;
235 if (!Expect(' '))
236 return FALSE;
237 // HTTP version (eg. HTTP/1.1)
238 if (!ReadSpecial(sVersion, sizeof(sVersion)))
239 return FALSE;
240 // CRLF
241 if (!ExpectCRLF())
242 return FALSE;
243
244 return TRUE;
245 }
246 }
248 return FALSE;
249}
CHAR sMethod[63]
Definition: http.h:34
CHAR sVersion[15]
Definition: http.h:32
BOOL ReadSpecial(LPSTR lpStr, UINT nLength)
Definition: http.cpp:142
CHAR sUri[255]
Definition: http.h:31
UINT nMethodNo
Definition: http.h:35
CHAR MethodTable[NUMMETHODS][8]
Definition: http.cpp:19
#define NUMMETHODS
Definition: http.h:12

Referenced by Parse().

◆ Skip()

VOID CHttpParser::Skip ( CHAR  sStr)
private

Definition at line 161 of file http.cpp.

162{
163 CHAR sTmp;
164
165 while (PeekChar(&sTmp) && (sTmp != sCh))
166 ReadChar(&sTmp);
167}

Referenced by EntityHeader(), GenerelHeader(), and RequestHeader().

Member Data Documentation

◆ bBadRequest

BOOL CHttpParser::bBadRequest

Definition at line 37 of file http.h.

◆ bUnknownMethod

BOOL CHttpParser::bUnknownMethod

Definition at line 36 of file http.h.

Referenced by Complete(), CHttpClient::OnRead(), and RequestLine().

◆ nHead

UINT CHttpParser::nHead

Definition at line 29 of file http.h.

Referenced by CHttpParser(), CHttpClient::OnRead(), PeekChar(), and ReadChar().

◆ nMethodNo

UINT CHttpParser::nMethodNo

Definition at line 35 of file http.h.

Referenced by CHttpClient::ProcessRequest(), and RequestLine().

◆ nTail

UINT CHttpParser::nTail

Definition at line 30 of file http.h.

Referenced by CHttpParser(), Complete(), PeekChar(), and ReadChar().

◆ sBuffer

CHAR CHttpParser::sBuffer[2048]

Definition at line 28 of file http.h.

Referenced by CHttpClient::OnRead(), PeekChar(), and ReadChar().

◆ sHeader

CHAR CHttpParser::sHeader[63]

Definition at line 33 of file http.h.

Referenced by EntityHeader(), GenerelHeader(), Parse(), and RequestHeader().

◆ sMethod

CHAR CHttpParser::sMethod[63]

Definition at line 34 of file http.h.

Referenced by RequestLine().

◆ sUri

CHAR CHttpParser::sUri[255]

Definition at line 31 of file http.h.

Referenced by CHttpClient::ProcessRequest(), and RequestLine().

◆ sVersion

CHAR CHttpParser::sVersion[15]

Definition at line 32 of file http.h.

Referenced by RequestLine().


The documentation for this class was generated from the following files: