Commit 68e96823809e05a6338c56c3dd90ad6307bb771e

Authored by Georg Hopp
1 parent 90df11c0

now stuff seems to work correct even if read does not provide a complete request…

… (tested with telnet)
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 typedef enum e_HttpRequestState { 9 typedef enum e_HttpRequestState {
10 HTTP_REQUEST_GARBAGE=0, 10 HTTP_REQUEST_GARBAGE=0,
11 HTTP_REQUEST_START, 11 HTTP_REQUEST_START,
12 - HTTP_REQUEST_REQEUST_LINE_DONE, 12 + HTTP_REQUEST_REQUEST_LINE_DONE,
13 HTTP_REQUEST_HEADERS_DONE, 13 HTTP_REQUEST_HEADERS_DONE,
14 HTTP_REQUEST_DONE 14 HTTP_REQUEST_DONE
15 } HttpRequestState; 15 } HttpRequestState;
@@ -134,7 +134,7 @@ void @@ -134,7 +134,7 @@ void
134 httpRequestParserParse(HttpRequestParser this) 134 httpRequestParserParse(HttpRequestParser this)
135 { 135 {
136 static HttpRequest request = NULL; 136 static HttpRequest request = NULL;
137 - char * data = this->buffer; 137 + static char * data; // static pointer to unprocessed data
138 char * line; 138 char * line;
139 int cont = 1; 139 int cont = 1;
140 static int header_idx; 140 static int header_idx;
@@ -143,6 +143,7 @@ httpRequestParserParse(HttpRequestParser this) @@ -143,6 +143,7 @@ httpRequestParserParse(HttpRequestParser this)
143 switch(this->state) { 143 switch(this->state) {
144 case HTTP_REQUEST_GARBAGE: 144 case HTTP_REQUEST_GARBAGE:
145 puts("==skip garbage=="); 145 puts("==skip garbage==");
  146 + data = this->buffer; // initialize static pointer
146 httpRequestSkip(&data); 147 httpRequestSkip(&data);
147 request = new(HttpRequest); 148 request = new(HttpRequest);
148 149
@@ -188,10 +189,10 @@ httpRequestParserParse(HttpRequestParser this) @@ -188,10 +189,10 @@ httpRequestParserParse(HttpRequestParser this)
188 } 189 }
189 190
190 header_idx = 0; 191 header_idx = 0;
191 - this->state = HTTP_REQUEST_REQEUST_LINE_DONE; 192 + this->state = HTTP_REQUEST_REQUEST_LINE_DONE;
192 break; 193 break;
193 194
194 - case HTTP_REQUEST_REQEUST_LINE_DONE: 195 + case HTTP_REQUEST_REQUEST_LINE_DONE:
195 puts("==read header=="); 196 puts("==read header==");
196 if (NULL == (line = httpRequestLineGet(&data))) { 197 if (NULL == (line = httpRequestLineGet(&data))) {
197 cont = 0; 198 cont = 0;
@@ -223,25 +224,40 @@ httpRequestParserParse(HttpRequestParser this) @@ -223,25 +224,40 @@ httpRequestParserParse(HttpRequestParser this)
223 case HTTP_REQUEST_HEADERS_DONE: 224 case HTTP_REQUEST_HEADERS_DONE:
224 puts("==headers done=="); 225 puts("==headers done==");
225 226
  227 + /**
  228 + * @TODO: here comes the body handling
  229 + */
226 this->state = HTTP_REQUEST_DONE; 230 this->state = HTTP_REQUEST_DONE;
227 break; 231 break;
228 232
229 case HTTP_REQUEST_DONE: 233 case HTTP_REQUEST_DONE:
230 puts("==request done=="); 234 puts("==request done==");
231 235
  236 + /**
  237 + * enqueue current request
  238 + */
  239 + this->request_queue->requests[(this->request_queue->nrequests)++] =
  240 + request;
  241 +
  242 + /**
  243 + * remove processed stuff from input buffer.
  244 + */
232 memmove(this->buffer, 245 memmove(this->buffer,
233 data, 246 data,
234 this->buffer_used - (data - this->buffer) + 1); 247 this->buffer_used - (data - this->buffer) + 1);
235 248
236 this->buffer_used -= data - this->buffer; 249 this->buffer_used -= data - this->buffer;
237 250
  251 + /**
  252 + * dont continue loop if input buffer is empty
  253 + */
238 if (0 == this->buffer_used) { 254 if (0 == this->buffer_used) {
239 cont = 0; 255 cont = 0;
240 } 256 }
241 257
242 - this->request_queue->requests[(this->request_queue->nrequests)++] =  
243 - request;  
244 - 258 + /**
  259 + * prepare for next request
  260 + */
245 this->state = HTTP_REQUEST_GARBAGE; 261 this->state = HTTP_REQUEST_GARBAGE;
246 262
247 break; 263 break;
Please register or login to post a comment