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